Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Single-Instance option for WinUI 3 #4662

Open
2 of 3 tasks
Leisvan opened this issue Apr 26, 2023 · 5 comments
Open
2 of 3 tasks

Add a Single-Instance option for WinUI 3 #4662

Leisvan opened this issue Apr 26, 2023 · 5 comments

Comments

@Leisvan
Copy link

Leisvan commented Apr 26, 2023

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:

  • WinUI
  • WPF
  • UWP
@mikebattista
Copy link
Collaborator

@Leisvan
Copy link
Author

Leisvan commented Apr 27, 2023

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.

@mikebattista
Copy link
Collaborator

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.

@snandaworld
Copy link

snandaworld commented Nov 8, 2023

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.

@tomysaw
Copy link

tomysaw commented Mar 30, 2024

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants