Search code examples
c#c++crashwindowmessagebox

Determine if program crashed


Possible Duplicate:
Detecting process crash in .NET

I'm writing a c# program that have to determine if another C++ game program (let's call it Foobar) is crashed or not. When the FooBar program crashes it's notifying the user about the crash with a MessageBox, if you OK that windows the program closes. So I guess I could determine if the program is crashed if that messagebox is opened/active. Problem I dont know how to do that. Or if there is any other better solution comes to your mind, please share it with me.

Edit: I can not edit the C++ program, and it's always a possibility that it will crash. I just need to know if it did.


Solution

  • Duplicate of Detecting process crash in .NET.

    The heartbeat is probably the way to go, but there is another way.

    When a process crashes, Windows first checks to see if a Just-In-Time debugger is configured on your system. If so, you can have that debugger attach itself to the process right before it crashes. Usually you would use this functionality to generate a memory dump as a process crashes. Whatever debugger you attach gets to know the PID and name of the crashing process. You can either utilize features of existing debugging tools, such as ADPlus, or write your own program and tell Windows that that is your Just-In-Time debugger and should be run when a process crashes. I believe you can set up a 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 HKLM\Software\Microsoft\Windows NT\Current Version\AeDebug\Debugger registry entry to '"DirectoryOfYourProgram\YourProgram.exe" -p %ld' where YourProgram.exe expects a PID passed in with the -p flag, your program will be called and passed the correct PID when a process crashes.