I have a piece of C# code, that calls a process, pointing to another executable. In some rare occasions an access violation happens and the latter gets terminated by operating system with message "program.exe has stopped working ... windows can check online for a solution, blah-blah...". I am able to kill and close the process using WaitForExit with a predefined timeout, but the mentioned window keeps hanging. Is it possible to somehow dismiss it ?
The code, which calls external program is as follows :
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.FileName = pathToExe;
startInfo.ErrorDialog = false;
startInfo.Arguments = arguments;
string error = "";
using (Process exeProcess = System.Diagnostics.Process.Start(startInfo))
{
try
{
if (!exeProcess.WaitForExit(timeout))
{
/// timed out
/// clean up, set err message
exeProcess.Kill();
error = "timed out";
}
else if (exeProcess.ExitCode != 0)
{
/// aborted itself on error
/// clean up, return err message
error = exeProcess.StandardError.ReadToEnd();
}
else
{
//finished correctly
//do some useful stuff
}
}
catch(Exception e)
{
error = e.Message;
}
}