Try this:
Process exe = Process.GetProcesses().FirstOrDefault(p => p.ProcessName.ToLower().Trim().StartsWith("conquer"));
if(exe != null)
{
exe.WaitForExit();
exe.refresh();
if(exe.HasExited)
{
Application.Exit();
Enviroment.Exit(0);
}
}
else
{
//Conquer process has already exited or was not running.
}
I also agree with @Naren this code should be run in a background worker thread. You shouldn't need to run this in a timer, in fact you shouldn't. If you run this is a background worker thread the exe.WaitForExit();
call will suspend the background thread until the process has exited.
If the application you are running this code in is dependant on the conquer process then if it is not running on startup you could start it yourself and then wait for exit... Again this code should be run in a background thread.
Process exe = Process.GetProcesses().FirstOrDefault(p => p.ProcessName.ToLower().Trim().StartsWith("conquer"));
if(exe == null)
{
exe = new Process();
exe.StartInfo.FileName = "conquer.exe"
exe.Start();
exe.WaitForExit();
exe.refresh();
if(exe.HasExited)
{
Application.Exit();
Enviroment.Exit(0);
}
}
if(exe != null)
{
exe.WaitForExit();
exe.refresh();
if(exe.HasExited)
{
Application.Exit();
Enviroment.Exit(0);
}
}