简体   繁体   中英

C# application crashes on debug

I have a multithreaded c# project. I have removed a lock, that locked unnecessarily shared objects, and tried to make those shared objects to be for single thread. The thing is now the process is crashing, with no error whats so ever - not in the event viewer or when I run in debug. Can anyone suggest a way for me to diagnose the error? Because the fact that visual studio just lets the process stop with nothing for me to work with makes me stuck. My last resort is WinDbg, and I would like to avoid that.

you could try to hook into unhandled app domain exceptions - http://msdn.microsoft.com/en-GB/library/system.appdomain.unhandledexception.aspx

and also check out unhandled thread exceptions: https://msdn.microsoft.com/en-GB/library/system.windows.forms.application.threadexception.aspx

(code from example in appdomain link)

using System;
using System.Security.Permissions;

public class Example 
{
   [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
   public static void Main()
   {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

      try {
         throw new Exception("1");
      } catch (Exception e) {
         Console.WriteLine("Catch clause caught : {0} \n", e.Message);
      }

      throw new Exception("2");
   }

   static void MyHandler(object sender, UnhandledExceptionEventArgs args) 
   {
      Exception e = (Exception) args.ExceptionObject;
      Console.WriteLine("MyHandler caught : " + e.Message);
      Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
   }
}
// The example displays the following output: 
//       Catch clause caught : 1 
//        
//       MyHandler caught : 2 
//       Runtime terminating: True 
//        
//       Unhandled Exception: System.Exception: 2 
//          at Example.Main()  

It's also a good idea to check the Exceptions that cause a Debugger-break in Visual studio.

You can find this unter Debug->Exceptions... or with Crtl+D, E

Maybe visual studio just skips the exception that is causing your crash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM