驳回;blah.exe已停止工作“;消息C#
我有一段C代码,它调用一个进程,指向另一个可执行文件。在某些罕见的情况下,会发生访问冲突,后者会被操作系统终止,并显示消息“program.exe已停止工作…windows可以联机检查解决方案,等等…”。我可以使用WaitForExit在预定义的超时时间内终止并关闭进程,但是上面提到的窗口一直挂起。是否有可能以某种方式将其驳回 调用外部程序的代码如下所示:驳回;blah.exe已停止工作“;消息C#,c#,windows,exe,unmanaged,terminate,C#,Windows,Exe,Unmanaged,Terminate,我有一段C代码,它调用一个进程,指向另一个可执行文件。在某些罕见的情况下,会发生访问冲突,后者会被操作系统终止,并显示消息“program.exe已停止工作…windows可以联机检查解决方案,等等…”。我可以使用WaitForExit在预定义的超时时间内终止并关闭进程,但是上面提到的窗口一直挂起。是否有可能以某种方式将其驳回 调用外部程序的代码如下所示: ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateN
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;
}
}
有一个Windows API调用SetErrorMode,允许禁用此行为。但是,您不能为另一个进程设置错误模式。因此,此解决方案意味着您可以控制“blah.exe”源代码。关于和主题的有用答案 另一个建议的解决方案是将外部程序作为windows服务运行