6

So I am writing an application that monitors a console application that was written by another developer. The console application is prone to crashing and because it runs all night i need my application to restart it.

Unfortunaltey when the console app crashes i get the windows message that says "blah has stopped working" And a button that says close program.

I am using System.Diagnostic.Process to start the console application but I cannot determine if the console application has crashed until AFTER the close program button is hit. Process.Responding is always true (there is no windows handle) Process.exited isnt fired till after the close program button is hit.

Any ideas would be greatly helpfull.

Thanks

5 Answers5

2

Disable the windows crash reporting feature. It gets notified by the kernel when a process fails. The process is alive until the crash reporting thingy is done with it.

The feature can be disabled per-process using some API. Disabling Windows error reporting (Dr. Watson) for my process Don't globally disable it to fix a local problem.

Community
  • 1
  • 1
usr
  • 168,620
  • 35
  • 240
  • 369
  • i disabled so it doesnt search for a solution but i still get a window pop up. – user1253149 Mar 06 '12 at 20:43
  • 5
    Implementing a system-wide change just for one application seems a touch heavy-handed. – Sam Axe Mar 06 '12 at 20:46
  • I was not clear in the original answer: The feature can be disabled per-process using some API. http://stackoverflow.com/questions/1134343/disabling-windows-error-reporting-dr-watson-for-my-process – usr Aug 24 '16 at 08:33
1

Look at ProcessStartInfo.ErrorDialog = false;

j0k
  • 22,600
  • 28
  • 79
  • 90
0
  1. this is not a good case for a console app. A windows service or a scheduled task would be a better fit.

  2. your console app is crashing, because you don't have any error handling

  3. as the other person said, your process is being hung by windows error reporting

If you want my advice, going with the little information that I have, I'll assume it has to be the way it is now, so wrap the whole process in a try/catch and deal with the exception in the catch block so it doesn't bubble up to windows error reporting. Then call the restart from there.

Edit: the person got a sufficient answer, but I'm leaving this up for googlers. I want to note that the wrapper application won't ever get control over the crash of the process without having turned off windows error reporting, so it's an important step in the process.

deltree
  • 3,756
  • 1
  • 30
  • 51
0

I do not know of any built-in method for handling this.. but you could write a debugger into your watchdog: http://www.codeproject.com/Articles/5275/Writing-a-Debugger-Part-2-The-Debug-Loop

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
-1

This seems to work for me:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo();
startinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startinfo.FileName = @"PATH TO EXE";
startinfo.Arguments = "Arg1 Arg2 Arg3";
startinfo.ErrorDialog = false;
startinfo.RedirectStandardError = true;
startinfo.UseShellExecute = false;
process.StartInfo = startinfo;           
process.Start();
process.WaitForExit();
process.Kill();
Anthony R
  • 173
  • 1
  • 8
  • I tried this suggestion, and it does not work. Are you sure that this removes the dialog for you? – Zero3 Mar 26 '22 at 01:43