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#.
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#.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
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
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
You mean there is no way to tell .net host to run only one instance of an application (using domains or something...)?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
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.
Code:private static System.Threading.Mutex m_SingleInstanceMutex; // in main: m_SingleInstanceMutex = new Mutex( true, @"Local\YourName", out returnValue ); if( ! returnValue ) { // instance of this executable already running }
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.