C# Close previous application instance
Continuing this post:
http://kseesharp.blogspot.com/2008/11/c-check-if-application-is-already.html
It is possible to close the currently running instance of the application:
static bool CloseApplicationAlreadyRunning()
{
string proc = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(proc);
if (processes.Length < 2) return (false);
foreach (Process process in processes)
{
if (process.Id != Process.GetCurrentProcess().Id)
{
process.CloseMainWindow();
if (process.WaitForExit(6000)) return (false);
else return (true);
}
}
return false;
}
Modify the timeout appropriately.
Asaf
http://asyncop.com/