When the user presses the close button in my form, I am executing a piece of code that stops a process (java.exe) via a messagebox. So if you press the "Yes" button the program scans through all the processes that are running and checks if the process is running. If the process is not running thehn kill the application.
The problem is that the message is popping up multiple times. This happens because he keeps activating the closing event, but I don't know how to code this the right way.
if (_isRunning)
{
if (MessageBox.Show("Are you sure you want to quit?", "Confirm Quit", MessageBoxButtons.YesNo) ==
DialogResult.Yes)
{
Stop();
_exited = true;
foreach (Process x in Process.GetProcesses())
{
while (x.Id == _processID)
{
Application.Exit();
e.Cancel = true;
return;
}
}
}
}
Any ideas?