0

i am launching an .exe like this

ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = stuff;
start.FileName = "test.exe";
try{
    using (Process proc = Process.Start(start))
    {
            proc.WaitForExit();
    ...
    }
}
catch
{
...}

from a thread. The problem is that sometimes "test.exe" crashes, opening a popup window saying

"application crashed blah blah.. looking for solution on internet blah blah"

having "test.exe" to crash, is expected, but what i need is or to close the popup window in order to release the thread, or "catch" the exe crash in the first place.

the try-catch in the code does not catch the crashing exe.

Could you please help? thank you

Yann
  • 180
  • 3
  • 14
  • to detect the crash you would need to check the exit code. – Darren Kopp Oct 05 '13 at 18:03
  • @DarrenKopp would a crashed program return an exit code before the windows "this program has crashed" popup appears? – Jason Sperske Oct 05 '13 at 18:06
  • Well, `WaitForExit` won't go until the program exits, whether that happens before or after that message happens i am not sure, but i'm guessing it's after (since you could attach a debugger via that message) – Darren Kopp Oct 05 '13 at 18:14

2 Answers2

2

As far as I know, you cannot achieve this from your application. It's a system-level setting. See eg How do I disable the 'Debug / Close Application' dialog on Windows Vista? for details on how to disable the dialogue, but note it has to be set per machine and affects all programs.

Community
  • 1
  • 1
David Arno
  • 42,717
  • 16
  • 86
  • 131
  • 1
    What about monitoring the process like this: http://stackoverflow.com/questions/3500634/how-to-check-if-process-is-not-responding – Jason Sperske Oct 05 '13 at 18:12
  • Nice find there Jason. It still doesn't completely solve the problem, but is better than nothing. – David Arno Oct 05 '13 at 18:27
0

With Windows Vista and higher a feature called Application Restart & Recovery is available. Amongst other things an application can register an handler procedure which is called by WER (Windows Error Reporting) on such Event. The method can do certain things. For example, you could write a stack trace, which is often useful when the application stops responding (AppHang).

Note that the function has to behave nivcely, i.e. follow certain rules what to do, when to do it and what not to do, otherwise WER will kill this recovery thread. I strongly suggest to look into MSDN.

By the way, your description lacks the exact crash message, you should add that Information. There are a number of possible reasons for what's called a "crash". Without that Information and given the code above it's kinda guessing.

JensG
  • 13,148
  • 4
  • 45
  • 55