Make an single instance app and showing the MainWindow when another instance is launched in VB.NET with WPF

StackOverflow https://stackoverflow.com/questions/7247261

  •  16-01-2021
  •  | 
  •  

Question

I am looking for a way to make my app running in a single instance mode and showing the MainWindow of the first instance when another instance is launched. I do a quick search on the internet but I did'nt find anything to open the MainWindow of the first instance or it was for Windows Form not for WPF.

I am working in VB.Net with Framework 4 and WPF.

Thanks

Was it helpful?

Solution

I wrote up an article for Winforms a while back at http://www.thinqlinq.com/Post.aspx/Title/Single-Instance-Winform-Issue. With winforms you can use the MyApplication_StartupNextInstance event handler to intercept subsequent launch requests and redirect them (navigating back to the MainWindow?) Unfortunately, I don't see that StartupNextInstance is still available with WPF. Maybe the pre 2.0 sample I posted at http://web.archive.org/web/20060528010613/http://www.avbsg.net/Uploads/SingleInstanceVB.zip can give you an idea of how to do this with WPF. My blog post walks through the general steps that I used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top