如何在 c# 中的应用程序中 运行 Windows IoT 应用程序
How to run a Windows IoT app within an app in c#
我正在尝试编写一个简单的主菜单应用程序,用户可以在其中单击一个按钮,然后它将启动一个已安装在 Windows 10 IoT 中的应用程序。 (以 "IoTCoreMediaPlayer" 应用为例)
这是我的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Data\USERS\DefaultAccount\AppData\Local\DevelopmentFiles\IoTCoreMediaPlayerVS.Debug_ARM.User\entrypoint\IoTCoreMediaPlayer.exe";
startInfo.Arguments = f;
Process.Start(startInfo);
}
然而,这不起作用并给我以下错误:
System.NotImplementedException: 'The method or operation is not implemented.'
下:
using Media_Center;
namespace System.Diagnostics
{
internal class Process
{
internal static void Start(string v)
{
throw new NotImplementedException();
}
internal static void Start(ProcessStartInfo startInfo)
{
throw new NotImplementedException(); <===
}
}
}
有人可以告诉我我做错了什么吗?
谢谢
您可以参考这个 sample,它演示了如何从另一个 UWP 应用程序启动一个 UWP 应用程序。
在此示例中,您可以找到操作代码:
private async void RunMainPage_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchmainpage://HostMainpage/Path1?param=This is param");
}
private async void RunPage1_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchpage1://Page1/Path1?param1=This is param1¶m1=This is param2");
}
private async Task LaunchAppAsync(string uriStr)
{
Uri uri = new Uri(uriStr);
var promptOptions = new Windows.System.LauncherOptions();
promptOptions.TreatAsUntrusted = false;
bool isSuccess = await Windows.System.Launcher.LaunchUriAsync(uri, promptOptions);
if (!isSuccess)
{
string msg = "Launch failed";
await new MessageDialog(msg).ShowAsync();
}
}
诀窍是在要启动的应用程序上指定 Windows 协议,并在 LaunchApp URI 中指定。
另外,如果你想启动一个外部进程(exe),你可以参考这个ExternalProcessLauncher示例。
我正在尝试编写一个简单的主菜单应用程序,用户可以在其中单击一个按钮,然后它将启动一个已安装在 Windows 10 IoT 中的应用程序。 (以 "IoTCoreMediaPlayer" 应用为例)
这是我的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Data\USERS\DefaultAccount\AppData\Local\DevelopmentFiles\IoTCoreMediaPlayerVS.Debug_ARM.User\entrypoint\IoTCoreMediaPlayer.exe";
startInfo.Arguments = f;
Process.Start(startInfo);
}
然而,这不起作用并给我以下错误:
System.NotImplementedException: 'The method or operation is not implemented.'
下:
using Media_Center;
namespace System.Diagnostics
{
internal class Process
{
internal static void Start(string v)
{
throw new NotImplementedException();
}
internal static void Start(ProcessStartInfo startInfo)
{
throw new NotImplementedException(); <===
}
}
}
有人可以告诉我我做错了什么吗? 谢谢
您可以参考这个 sample,它演示了如何从另一个 UWP 应用程序启动一个 UWP 应用程序。 在此示例中,您可以找到操作代码:
private async void RunMainPage_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchmainpage://HostMainpage/Path1?param=This is param");
}
private async void RunPage1_Click(object sender, RoutedEventArgs e)
{
await LaunchAppAsync("test-launchpage1://Page1/Path1?param1=This is param1¶m1=This is param2");
}
private async Task LaunchAppAsync(string uriStr)
{
Uri uri = new Uri(uriStr);
var promptOptions = new Windows.System.LauncherOptions();
promptOptions.TreatAsUntrusted = false;
bool isSuccess = await Windows.System.Launcher.LaunchUriAsync(uri, promptOptions);
if (!isSuccess)
{
string msg = "Launch failed";
await new MessageDialog(msg).ShowAsync();
}
}
诀窍是在要启动的应用程序上指定 Windows 协议,并在 LaunchApp URI 中指定。
另外,如果你想启动一个外部进程(exe),你可以参考这个ExternalProcessLauncher示例。