Multiple Instances of App

DotNET Fan 271 Reputation points
2024-09-19T08:19:31+00:00

Hi UWP experts,

So i have enabled multiple instances of my app through the package manifest

desktop4:SupportsMultipleInstances="true" and it works perfectly fine when the app is selected from the windows start menu and opens up multiple instances . The app has an option to open the same app in another process . How to programatically open it similiar to open multiple instances from start up menu?

I don't wont to go via the secondary window approach using a new dispatcher thread from the current app.

Thanks

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 19,051 Reputation points Microsoft Vendor
    2024-09-19T09:22:10.08+00:00

    Hi @DotNET Fan ,

    It is recommended to register a protocol to launch your UWP app.

    App,xaml.cs

    protected override void OnActivated(IActivatedEventArgs args)
    {
        // Window management
        Frame rootFrame = Window.Current.Content as Frame;
        if (rootFrame == null)
        {
            rootFrame = new Frame();
            Window.Current.Content = rootFrame;
        }
        rootFrame.Navigate(typeof(MainPage), args);
        Window.Current.Activate();
    }
    

    MainPage.xaml.cs

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        var uri = new Uri("test-app2app:");
        var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    }
    

    Package.appxmanifest

      <Applications>
        <Application Id="App"
          Executable="$targetnametoken$.exe"
          EntryPoint="UWPlaunchTest.App"
          desktop4:SupportsMultipleInstances="true">
          
          <Extensions>
            <uap:Extension Category="windows.protocol">
              <uap:Protocol Name="test-app2app" ReturnResults="always">
                <uap:DisplayName>Test app-2-app</uap:DisplayName>
              </uap:Protocol>
            </uap:Extension>
          </Extensions>
          
          <uap:VisualElements
            DisplayName="UWPlaunchTest"
            Square150x150Logo="Assets\Square150x150Logo.png"
            Square44x44Logo="Assets\Square44x44Logo.png"
            Description="UWPlaunchTest"
            BackgroundColor="transparent">
            <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
            <uap:SplashScreen Image="Assets\SplashScreen.png" />
          </uap:VisualElements>
        </Application>
      </Applications>
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.