Why does Microsoft Visual C# 2008 Express Edition debugger randomly exit?

前端 未结 4 407
鱼传尺愫
鱼传尺愫 2021-01-14 03:34

I am writing a multi-threaded Windows application in Microsoft Visual C# 2008 Express Edition. Recently, the debugger has been acting strangely.

While I am Stepping

相关标签:
4条回答
  • 2021-01-14 04:11

    I've seen this a few times. It generally happens when there's a context switch to another thread. So you might be stepping through thread with ID 11, you hit F10, and there's a pre-emptive context switch so now you're running on thread ID 12 and so Visual Studio merrily allows the code to continue.

    There are some good debugging tips here:

    Tip: Break only when a specific thread calls a method: To set a per-thread breakpoint, you need to uniquely identify a particular thread that you have given a name with its Name property. You can set a conditional breakpoint for a thread by creating a conditional expression such as "ThreadToStopOn" == Thread.CurrentThread.Name .

    You can manually change the name of a thread in the Watch window by watching variable "myThread" and entering a Name value for it in the value window. If you don't have a current thread variable to work with, you can use Thread.CurrentThread.Name to set the current thread's name. There is also a private integer variable in the Thread class, DONT_USE_InternalThread, this is unique to each thread. You can use the Threads window to get to the thread you want to stop on, and in the Watch window, enter Thread.CurrentThread.DONT_USE_InternalThread to see the value of it so you can create the right conditional breakpoint expression.

    EDIT: There are also some good tips here. I found this by googling for 'visual studio prevent thread switch while debugging'.

    0 讨论(0)
  • 2021-01-14 04:23

    You ought to take a look at this KB article and consider its matching hotfix.

    EDIT: the hotfix does solve these kind of debugging problems. Unfortunately, the source code changes for the hotfix didn't make it back into the main branch and VS2010 shipped with the exact same problems. This got corrected again by its Service Pack 1.

    0 讨论(0)
  • 2021-01-14 04:34

    I find using a logfile is very handy when dealing with multiple threads.

    Debugging threads is like the Huysenberg principle - observe too closely and you'll change the outcome !

    0 讨论(0)
  • 2021-01-14 04:34

    Try this http://support.microsoft.com/kb/957912. Worked for me.

    0 讨论(0)
提交回复
热议问题