How to know wheather a exe is running or not...
-
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed. what to do please let me know
-
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed. what to do please let me know
check out this code string aModuleName = system.Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName; string aProcName = System.IO.Path.GetFileNameWithoutExtension(aModuleName); if (system.Diagnostics.Process.GetProcessesByName(aProcName).Length>1) { Application.Exit(); } Navin
-
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed. what to do please let me know
-
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed. what to do please let me know
You can use a Mutex. Here is a piece of code that shows how to do it: In program.cs:
private static System.Threading.Mutex \_mutex; private const string \_mutexName = "Company\_Product\_MUTEX"; /// /// The main entry point for the application. /// \[STAThread\] static void Main() { //Allow only one instance for this app to be active try { //try to open existing mutex \_mutex = System.Threading.Mutex.OpenExisting(\_mutexName); if (\_mutex != null) return; //exit program; } catch { //There was no existing mutex so create mutex try { \_mutex = new System.Threading.Mutex(true, \_mutexName); } catch { }; } Application.ApplicationExit += new EventHandler(Application\_ApplicationExit);
/// do rest of the code, like Application.Run() etc.
} static void Application\_ApplicationExit(object sender, EventArgs e) { //Release Mutex if (\_mutex != null) { \_mutex.ReleaseMutex(); } }
That should do the trick.
-
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed. what to do please let me know
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters