How can we make a single instance application in C#? It is easy with VB.Net,only a checkbox. But I couldn't find a HowTo for C#.

05-26-2008

Magos

At startup enumerate all available processes and check their name with the name of the currently running process. If equal (and the process id's differ) then it is already running and you could:
a) Shutdown and print an error message
b) Focus on the already running process

05-27-2008

siavoshkc

You mean there is no way to tell .net host to run only one instance of an application (using domains or something...)?

05-27-2008

nvoigt

Use a named mutex. If you get it, your process is the first to run. If you fail to get it, there is already an instance running. It's way faster than scanning processes, plus you cannot manipulate it as easily as renaming a process.