All, I am trying to prevent multiple instances of an app, What I want to do is closing the last process, and running a new process for the app. Currently I knew I can stop running multiple instances for a winform application like this post. But I want to know how to close the last one safely. I don't want to use the Process.kill
method to terminate the app. I want to close it safely. So far I think the code should look like below . please help to review it .thanks.
[STAThread]
static void Main()
{
using(Mutex mutex = new Mutex(false, "Global\\" + appGuid))
{
if(!mutex.WaitOne(0, false))
{
MessageBox.Show("Instance already running");
//close the last one.
//......I don't know how to make it.
}
Application.Run(new Form1());
}
}
private static string appGuid = "c0a76b5a-12ab-45c5-b9d9-d693faa6e7b9";