TemplateStudio icon indicating copy to clipboard operation
TemplateStudio copied to clipboard

Add a Single-Instance option for WinUI 3

Open Leisvan opened this issue 2 years ago • 5 comments
trafficstars

Is your feature request related to a problem? Please describe.

WinUI apps are multi-instance by default, and it isn't straightforward to make an app single-instance.

Describe the solution you'd like

If the TemplateStudio had a Single-Instance option for WinUI that would save us all some time and effort.

Describe alternatives you've considered

No response

Additional context

No response

Applies to the following platforms:

  • [X] WinUI
  • [X] WPF
  • [ ] UWP

Leisvan avatar Apr 26 '23 17:04 Leisvan

Single-instance samples are shown at https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/applifecycle/applifecycle-instancing#how-the-windows-app-sdk-instancing-differs-from-uwp-instancing.

Have you been able to get that working?

mikebattista avatar Apr 27 '23 15:04 mikebattista

I get it working (kind of). But it would be quite a boost if TemplateStudio comes with an option to setup a Single-Instance app.

Leisvan avatar Apr 27 '23 15:04 Leisvan

Can you share your code?

There's quite a few ways to handle things so there'd need to be a canonical way to handle it that most people would want to put it in the templates.

The samples seem pretty simple for the basic case of redirecting all instances to another single instance.

mikebattista avatar Apr 27 '23 16:04 mikebattista

Single-instance samples are shown at https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/applifecycle/applifecycle-instancing#how-the-windows-app-sdk-instancing-differs-from-uwp-instancing.

Have you been able to get that working?

I have been able to get it working with a Blank WinUI Project app, But when I try to make the App single instanced with the project which is created using Templated studio is failing to raise OnActivated() event.

It goes well till keyinstace.RedirectActivationToAsync(args).AsTask().Wait();

After this line of code, execution won't continue and throws an Aggregate exception.

OnActivated() event won't be triggerred forever.

snandaworld avatar Nov 08 '23 17:11 snandaworld

https://blogs.windows.com/windowsdeveloper/2022/01/28/making-the-app-single-instanced-part-3/ This one also helps but contains an issue. Program.Main must remain synchronous (static void Main) otherwise it loses [STAThread]

tomysaw avatar Mar 30 '24 05:03 tomysaw