简体   繁体   中英

Curious Visual Studio 2010 Debugging Behavior in Windows 7 x64

Apparently, Windows eats my errors. Literally. I have this C# .Net 4.0 @ VS 2010 application I'm working on and it eventually crashed. Windows came up and said it did some "compatibility" modifications to allow the application to "work better", then my application window just disappeared and bye-bye debug mode.

I ran again. When the application was supposed to crash, it just quit, no errors, no nothing.

Anyway, I knew what the error was and I fixed it. It was all ok for a few days.

But today, I implemented some simple threading via ThreadPool. What happens is that something crashes in my thread and here's the awesome stuff:

Visual Studio navigates in the solution, opening the file AND THE FUNCTION which crashes, but then its stops short of breaking my application and showing me the error. It just opens the proper file, the proper function, and my thread quits, the progress bar on my window keeps spinning forever and that's it... stuck in limbo...

To make matters even more complicated (and this happens even in single-threaded scenarios), check this out: I tried trapping THE ENTIRE program. This should technically catch ANY error that occurs. Well guess what, it doesn't. I see no Error written in my Error Log.

What's interesting is that it seems to happen only when accessing the database via my strong-typed datasets (which use the MySQL libraries for .Net). Other errors are logged successfully.

But I used the same MySQL libraries on Windows XP a few months ago and I always had all errors logged and, when debugging with Visual Studio, shown to me at run-time.

  try //Main application loop. Logs all errors, yeah.
  {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    ETKSession.DebugMode = false;
    Application.Run(new frmLogin());
  }
  catch (Exception ex)
  {
    AErrorLogging.Log(ex); //This is a tested error log writer of mine which usually worked.
    if (ETKSession.DebugMode) throw new Exception(ex.Message, ex);
  }

Any ideas about what the hell is going on in there?! I tried clicking on some links when Windows told me of its "compatibility improvements" but all I got was stupid Support Center links and nothing relevant. I can't even CHANGE those compatibility settings. Upon investigating my application's EXE properties, I find absolutely no compatibility changes made ::- (. Extremely frustrating!

I would try to catch exception this way instead :

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    ETKSession.DebugMode = false;
    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    Application.Run(new frmLogin());
}

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
    AErrorLogging.Log(ex); //This is a tested error log writer of mine which usually worked.
    if (ETKSession.DebugMode) throw new Exception(ex.Message, ex);
}

You mentioned earlier that Form_Load and Timers does not contains try catch code. I think adding a try catch with your handler in them could help : there is an existing issue on 64bits where exceptions are silently dropped from Form_Load.

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