Search code examples
c#windows-iot-core-10

How to run a Windows IoT app within an app in c#


I am trying to write a simple main menu app where the user can click on a button and then it will launch a app that is already installed in Windows 10 IoT. (Its the "IoTCoreMediaPlayer" app as a sample)

Here is my code:

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);
    }

This however does not work and gives me the following error:

System.NotImplementedException: 'The method or operation is not implemented.'

under:

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(); <===
    }
}
}

Could someone please tell me what I am doing wrong? Thanks


Solution

  • You can refer to this sample which demonstrates how to launch an UWP app from another UWP app. In this sample you find the operation code:

    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&param1=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(); 
        } 
    }
    

    The trick is set specify Windows Protocol on the application you want to launch, and specify that in the LaunchApp URI.

    In addition, if you want to launch an external process(exe), you can refer to this ExternalProcessLauncher sample.