Condividi tramite


How do I ensure a single instance of my Windows Form application?

I get this question quite a bit... One trick to ensuring a single instance of your Windows application is to create a Mutex on startup. Mutexes can cross process boundaries so they provide a great mechanism for checking if your application is already running. Once you have determined that your application is running you need to bring it to the foreground. Here are some tutorials that I have found on the web that go into more detail:
- https://www.codeproject.com/csharp/cssingprocess.asp
- https://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=711&printer=t
- https://www.ai.uga.edu/~mc/SingleInstance.html
- https://www.devcity.net/forums/faq.asp?fid=30&cat=General&#TID25519

Note for .NET Compact Framework developers, by default on the Pocket PC and Smartphone platforms the .NET Compact Framework will ensure this “one instance” behaviour for you - it is part of the framework. Developer targeting Windows CE .NET platforms should check out this sample:
- https://www.gotdotnet.com/Community/UserSamples/Download.aspx?SampleGuid=9A07CA83-0FD2-44B7-82D0-BD3CFA84E294

Comments