How to find out that the process crashed

In my console application, I have code that looks like

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

This works fine, and it waits for MSSQLExecutor.exe to complete its task, after which the application continues.

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

I want to avoid this because MY application will work as a service without user interaction.

After This I wanna to move on whit my app

+7
source share
4 answers

Dialog prevents the existence of this process.

  • If MSSQLExecutor is your application, you should fix this problem. But you can achieve the goal (by hiding the dialogue). 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 } 
  • If MSSQLExecutor not your application, you can disable Dr. Watson

    R. Watson is an application debugger included in the Microsoft Windows operating system.

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

More Infromation

+7
source

This is a common problem when working with external processes. From here, I would suggest setting the 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 "); 
+5
source

Accordingly: Detecting a Process Failure in .NET

Alternatively, you can call Process.Kill if you only want to wait for the process to complete.

+1
source

If you do not want to block waiting for the process to complete, do not call Process.WaitForExit (). What is the purpose of this? If you just need to know when it ends, register for the Process.Exited event. In the Process.Exited event, you can check Process.ExitCode to see if it ended due to a failure or not.

0
source

All Articles