I have an application that I restart at 2 am every morning using
Application.Restart();
the problem is that a inspection a couple of weeks later shows that there are 6 or so instances running.
I tried to limit the number of instances by using
bool IsOwned;
Mutex m = new Mutex(true, Name, out IsOwned);
if (!IsOwned)
Environment.Exit(0);
But this didn't work as for some reason the recently stopped instance was still visible...or at least that's my interpretation and as a result the application didn't reatart.
Where have I gone wrong?
Make sure that you hook on application exit event a method that releases the mutex and closes it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With