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
- Anonymous
June 04, 2004
Hi,
How can i have make sure that the Some window is always on top of application and not top on other application windows - Anonymous
June 29, 2004
Thanks alot! This code does work for Windows CE.
http://www.gotdotnet.com/Community/UserSamples/Download.aspx?SampleGuid=9A07CA83-0FD2-44B7-82D0-BD3CFA84E294 - Anonymous
July 28, 2004
nice work. thanks - Anonymous
January 21, 2009
The comment has been removed - Anonymous
April 09, 2009
Therearemanyresourcesonline,Ijustwanttoaddabookmarkatmyownplace. A