Process failure detection in .NET.

Is there a way to determine if my program crashed? Currently, the solution I found is to look at Process.ExitCode and examine the value:

  this.STProcess = Process.Start(this.CreateProcessStartInfo()); this.STProcess.WaitForExit(); if (STProcess.ExitCode != 0) { //raise error event... } 

I wanted to know if there is a more elegant (and accurate) way to do this?

I would prefer answers in C #, and using P / Invoke is also great.

PS - I need to work with Windows XP / Vista / 7

+5
source share
3 answers

Not.

If you do not influence the process in any way (write errors to the Eventlog? A file), you have no external way to find out that the process crashed, as far as I know. For you, it's just a process that has gone. Even Windows is not going to store this information anywhere I know. It no longer exists, and if the process somehow does not store the details, they have disappeared.

+5
source

For Windows 7, there is an application restart and recovery API . For .NET, you can use the Windows API Code Code .

General, you can periodically search for the existence of a process (watchdog application).

+2
source

If the process crashes, Windows first checks to see if the Just-In-Time debugger is configured on your system. If so, you can force this debugger to join the process just before it crashes. Normally you should use this function to dump the memory if the process crashes. No matter which debugger you attach, it will recognize the PID and the name of the failure process. You can either use the features of existing debugging tools, such as ADPlus, or write your own program and tell Windows that it is your Just-In-Time debugger and should start when the process fails. I believe that you can configure the JIT debugger specifically for any process name.

See http://msdn.microsoft.com/en-us/library/5hs4b7a6(v=VS.80).aspx

I think that if you set the registry entry HKLM \ Software \ Microsoft \ Windows NT \ Current Version \ AeDebug \ Debugger to "DirectoryOfYourProgram \ YourProgram.exe" -p% ld ', where YourProgram.exe expects the PID passed in with with the -p flag, your program will be called and will give the correct PID if the process fails.

+2
source

All Articles