I have the following code that checks if my application is already running:
if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Count() > 1)
{
MessageBox.Show("Multiple instances!");
Process.GetCurrentProcess().Kill();
}
Now, on some point in my app I use
Application.Restart();
Sporadically, when the app is restarting I get the message from the above IF statement.
How could I prevent this of happening? Can I assure somehow that all my processes will be closed before Application.Restart() or can I somehow make sure that when the app is starting after Application.Restart() it will NOT see the previous processes running so that it will NOT throw me the message box?