hello friends,
how to check my application file runing or not if already runing then it should say arealy logged in when i double click on Icon or exe..
reply me ASAP...
EXE file is existing in c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Posted May 20, 2011, 1:48 AM EDT
System.Diagnostics.Process[] process= System.Diagnostics.Process.GetProcessesByName("exeName");
if (process.Length > 0)
MessageBox.Show("Application is already running");
Sam HobbsRank #107 · 20.5K reputationPosted May 20, 2011, 11:57 PM EDT
bool WasCreated;
const string MutexName = "WhateverNameYouWant";
Mutex m = new Mutex(true, MutexName, out WasCreated);
if (!WasCreated)
{
// MessageBox.Show("A previous instance exists");
return;
}
Also, after the "Application.Run(new Form1());" you need to also do the following:
GC.KeepAlive(m);
That line is not important for small programs, but always use it anyway when using the above code that uses the Mutex.