To check if an application is running and continue or return back to your previous condition this should make your life easier in order not to exit from any of your current processes
protected override void OnFormClosing(FormClosingEventArgs e)
{
Process[] pname = Process.GetProcessesByName("ConsoleApplication");
if (pname.Length == 0)
{
}
else
{
MessageBox.Show("You cannot exit until the process has finished");
e.Cancel = true;
}
}