How to know that Process has crashed

10,488

Solution 1

The Dialog prevents that the process exists.

  1. If MSSQLExecutor is your Application you should fix the problem. But you can reach the goal (hiding the Dialog). Handle Application.ThreadException and AppDomain.CurrentDomain.UnhandledException

    Application.ThreadException +=new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
    
    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        // log the exception
    }
    
    static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
    {
        // log the exception
    }
    
  2. If MSSQLExecutor is not your Application you can deactivate Dr. Watson

    Dr. Watson is an application debugger included with the Microsoft Windows operating system.

    • Click Start, click Run, type regedit.exe in the Open box, and then click OK.
    • Locate and then click the following registry key:
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug
    • Click the AeDebug key, and then click Export Registry File on the Registry menu.
    • Delete the AeDebug key.

More Infromation

Solution 2

This is a frequent problem running outside processes. From here I would suggest setting a maximum timeout value for this application.

Process DKU = new Process();
DKU.StartInfo.FileName = "MSSQLExecutor.exe";
DKU.Start();
DKU.WaitForExit(10*60*1000);

if (!DKU.HasExited)
        DKU.Kill();

Console.WriteLine("lets move on ");

Solution 3

Relevent: Detecting process crash in .NET

Also, you could call Process.Kill if you only wanted to wait so long for the process to finish.

Share:
10,488
adopilot
Author by

adopilot

Hello ! I am coming from Bosnia and Herzegovina,Sarajevo capital, I work in family firm as an IT administrator, My primary task is to eventing works well and lot of other stuff such as buying software, buying equipment, administrating SQL servers and much more. Our Company business is retrial and We have shops all around country with more than 300 working station with more than 1000 employed. In free time I try to learn programing in .NET and I having fun driving motocross bike, some time by summer I do a solar gliding flaying as sport pilot. If You fund my English is bad do not be maid my education was mostly during the war in Bosnia, in that time we did not have to study much for good ratings. Best regards Admir

Updated on June 14, 2022

Comments

  • adopilot
    adopilot almost 2 years

    In my console application I have code which looks like

        Process DKU = new Process();
        DKU.StartInfo.FileName = "MSSQLExecutor.exe";
        DKU.Start();
        DKU.WaitForExit();
        Console.WriteLine("lets move on ");
    

    This is working fine and it waits until MSSQLExecutor.exe finishes its job, then after that the app continues.

    My problem is that sometimes MSSQLExecutor.exe crashes and Windows by default shows a dialog for ending the program. At that point my application will wait forever for the user to click the Close button.

    I want to avoid this because MY application is going to run as a service without user interaction.

    After This I wanna to move on whit my app

  • cwharris
    cwharris over 12 years
    Interesting. And if Dr. Watson isn't enabled, the process will die, as usual? And does that mean Process.WaitForExit() will stop blocking?
  • jhocking
    jhocking over 6 years
    fyi I'm investigating if this'll solve a problem I'm encountering; it certainly looks like it. Additional info about Dr. Watson, including what looks like a safer way of disabling it than deleting the registry key: techdows.com/2009/03/… ccm.net/faq/6610-how-to-delete-disable-dr-watson-debugger
  • mrid
    mrid over 5 years
    @dknaack should I put this code in Program.cs or each of my forms do it doesn't crash on clients' systems ?