开发者

Can I catch APPCRASH of command line app launched with C#'s System.Diagnostic.Process()?

I need to write a C# application calling a command line tool (probably written in C), of which I know that it's unstable开发者_如何学Go. I wonder if it's possible to catch random crashes of this tool in my application.

It would be enough to handle these crashes by terminating my app and writing a log message indicating that the tool has crashed.

This is how I call it (details like Process.Startinfo settings omitted):

Process exeProcess = new Process();
exeProcess.Start();
exeProcess.WaitForExit();
exeProcess.Close();

I can reproduce one particular kind of crash due to bad input data (c0000005 Access Violation Exception), so I could check for its preconditions before starting the process. But I'm sure that in production other kinds of crashes would occur.


There's not a whole lot predictable about a process that crashes violently. If it was due to an hardware exception, like AccessViolation, then there are some reasonable odds that the process exit code will be a good indicator. Use Process.ExitCode after WaitForExit() to read it. A value of 0 usually indicates success, although that's up to the app as well.


Could try to list the processes let's say 10 times second. If your exe is closed, it crached.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜