Application Opening again and again
-
hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem
-
hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem
In the Main method, Use Process class to determine if an instance of your program is already running. If running then display an Error Message and Close. Otherwise start the Application. USe the following method to test if the application is running.
public static bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
} -
hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem
You can scan a list of processes but if someone renames the executable file that will not work. On the other hand using a mutex is much more reliable way of checking.
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem
Hi, use a Mutex to make your app "single instance". There are several CP articles on the subject, here is one[^] of them. BTW: do not rely on process names, since they may be changed, and you might not get access to all of them. :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages