How to debug a disappearing application

On a Windows 2003 server, I have a clean .NET 3.5 C# application (no unmanaged code). It connects to various other remote systems through sockets and acts as a data hub. It works for 10-15 hours without problems, but from time to time it just disappears. If I watch the application using the task manager, the memory usage remains constant.

In the Main() function, I end the call to the rest of the application in the try .. catch , which it just completely removes β€” the catch block, which catches the exception in the file, is ignored. If I manually create an exception for testing, the catch block is called.

Before entering try .. catch I do:

 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); 

There is Dr. Watson on the system, but nothing is written to the DRWTSN32.EXE directory.

How can I catch all this exception?

+4
source share
5 answers

Try using Microsoft debugging tools. You can download them from here .

Use adplus to capture the crash and then windbg to analyze it.

adplus -crash -pn your.exe -quiet

Great information on debugging windows on this blog .

+7
source

If this is a Windows Forms application, it is likely that the unhandled exception gets to the window message pump, so you will never see it. To handle this, see my answer here .

If it is a Windows service, the exception may appear in the background thread and not be redirected back to your main thread. To handle this, you need to translate any background thread back to the main thread, and the exception will be thrown there so you can catch it.

If this is a console application, then I'm a bit puzzled.

EDIT . Your comment says this is a Windows Forms application. In this case, you probably do not see the exception, because it is handled by the built-in Windows Forms exception handler, which by default does the following:

  • Catches an unhandled managed exception when:
    • no debugger and
    • An exception occurs when processing window messages and
    • jitDebugging = false in App.Config.
  • Shows a dialog for the user and prevents the termination of the application.

You can disable this behavior by setting jitDebugging = true in App.Config. You can then see the unhandled exception by registering for the Application.ThreadException event, for example. in C #:

 Application.ThreadException += new Threading.ThreadExceptionHandler(CatchExceptions); 
+3
source

You can also attach WinDBG at startup and enable breakpoints in .NET exceptions. Then you can make !printexception to see what happens.

+1
source

EventLog may have an application trace.

I got a .Net application that is not able to catch the exception. Each time this happened, an EventLog was recorded.

To view the event log, simply enter EventVwr at the command line or run the field.

+1
source

If this is a Windows Forms application, you can try Application.ThreadException .

0
source

All Articles