tags:

views:

185

answers:

2

Is there a way to determine that a process that my program started has 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 of doing this?

I would prefer answers in C# and using P/Invoke is fine as well.

P.S - I need to work on windows XP/Vista/7

+1  A: 

For Windows 7, there is Application Restart and Recovery API. For .NET you can use Windows API Code Pack.

Generaly, you can periodically search for process existence (watchdog application).

Igor
Thanks, but I need a solution that will run on windows XP as well.besides - I need to know if a process has crashed, not exited.
Shai Rubinshtein
+2  A: 

No.

Unless you can influence the process in some way (writing errors to the Eventlog? A file) you have no external way to know that a process crashed, as far as I know. For you it's just a process that went away. Not even Windows is going to keep this information anywhere I know. It doesn't exist anymore and unless the process somehow kept the details, they are gone.

Benjamin Podszun