public void Close()
{
if (_closed || !_ownProcess)
return;
if (_debug)
{
Console.WriteLine("Debug mode: Closing app " + _cmdLine + " - hit Enter to continue");
Console.ReadLine();
}
// Process.CloseMainWindow is too slow
PostMessage(_hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
if (! _p.WaitForExit(2000) && !_debug)
{
try
{
_p.Kill();
}
catch (InvalidOperationException)
{
// process may have already died in the meantime
}
}
_closed = true;
}