I currently have mutex in my app that allows only 1 instance to run. My question is, how do I take this code now, and transform it to close the currently running instance and allow a new one to open?
The problem I am trying to solve: My app takes in args and needs to be reopened often with new params. Currently, without mutex it can open an infinite number of times. I would like only 1 instance with the newest set of params to run.
Thanks,
Kevin
Some Code
bool createdMutex = true;
Mutex mutex = new Mutex(true, "VideoViewerApp", out createdMutex);
if (createdMutex && mutex.WaitOne())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmVideo(args[0], args[1], args[2], args[4], args[5]));
mutex.ReleaseMutex();
}
mutex.close();
The mutex was not meant for interprocess event notification, so there is no way to close another process by using mutexes. What I would recommend would be to do something like what is recommended in this question.
I’ll combine the two answers there into something like what I’ve used: