为什么Visual Studio在调试时停止?

时间:2021-06-23 02:55:54

Sometimes, while I am debugging a c# application, I will hit a break point and when I try to continue, step or step into, it just does nothing. The yellow line highlighting the current line goes away, but it never reaches the next line. The app is still frozen like I am on a breakpoint and I can do nothing but hit the stop debugging button and restart. This doesn't happen all the time, but once it starts on an app it seems like it always happens after that for that app. I have found that adding the following code just before the class declaration "fixes" the problem for that app, but am very curious as to why this is happening.

有时候,当我调试一个c#应用程序时,我会遇到一个断点,当我尝试继续,步入或进入时,它什么也没做。突出显示当前行的黄线消失,但它从未到达下一行。应用程序仍然像我在断点处一样冻结,除了点击停止调试按钮并重新启动,我什么也做不了。这不会一直发生,但一旦它在应用程序上启动,它似乎总是发生在该应用程序之后。我发现在类声明之前添加以下代码“修复”该应用程序的问题,但我很好奇为什么会发生这种情况。

[System.Diagnostics.DebuggerDisplay("Form1")]

Additional details: I have not noticed any kind of pattern as to what the particular line does when it freezes. Most of the apps I write use threading, so there is a decent chance this is happening within a thread every time.

其他细节:我没有注意到特定线冻结时的任何模式。我编写的大多数应用都使用线程,因此每次在线程中发生这种情况的可能性很小。

7 个解决方案

#1


2  

I've seen stalling problems where the debugger is trying to evaluate the variables shown in the Auto/Local windows. If the evaluation is complicated then it can cause significant stalls.

我已经看到调试器试图评估自动/本地窗口中显示的变量的停滞问题。如果评估很复杂,那么它可能会导致严重的停顿。

You can turn the auto-evaluation off through Tools|Options and it does make a big difference.

您可以通过工具|选项关闭自动评估,它确实会产生很大的不同。

#2


2  

I have come across with this kind of behavior, though this is my first time.

我遇到过这种行为,虽然这是我的第一次。

I have got through this problem, by two ways

我通过两种方式解决了这个问题

  1. Your way of putting this attribute, [System.Diagnostics.DebuggerDisplay("Form1")]
  2. 你放置这个属性的方法,[System.Diagnostics.DebuggerDisplay(“Form1”)]

  3. Turning off Tools->Options->Debugging->General->Enable Property evaluation and other implicit function calls.
  4. 关闭工具 - >选项 - >调试 - >常规 - >启用属性评估和其他隐式函数调用。

I am still debugging my code but It seems to me that some of the Autos evaluation is failing (possibly throwing an exception), which is possibly crashing the debugger.

我仍在调试我的代码,但在我看来,一些Autos评估失败(可能抛出异常),这可能会使调试器崩溃。

Please let us know if this is also your case.

如果您也是这样,请告诉我们。

#3


1  

What sort of code are you debugging?

你在调试什么样的代码?

When you "step into" are you calling your own .NET code, or calling a native library, or an external assembly that you don't have the pdb files for? Either of these situations would cause the debugger to freeze while the external code was executing.

当你“步入”你是在调用自己的.NET代码,还是调用本机库,或者你没有pdb文件的外部程序集?这些情况中的任何一种都会导致调试器在外部代码执行时冻结。

#4


1  

If you debug multithreaded application you might be changing of thread. You can switch between Thread with the "Thread windows" while debugging to be able to see again where the debug yellow line is.

如果您调试多线程应用程序,您可能正在更改线程。您可以在调试时使用“Thread windows”在Thread之间切换,以便能够再次查看调试黄线所在的位置。

#5


0  

My psychic debugger says that you're missing symbols for something and that VS is hitting the network trying to look them up. Try setting your symbol path to something weird like C:\foo.

我的通灵调试器说你错过了某些东西的符号,VS正在试图查找它们。尝试将符号路径设置为奇怪的东西,如C:\ foo。

#6


0  

dead-lock seems likely in your case. Press the pause button and look at the threads view next time it happens.

你的情况似乎很可能是死锁。按下暂停按钮,下次发生时查看线程视图。

#7


0  

I have seen this type of behavior when my DB was being very slow, NHibernate is trying to write to it under the hood, and the whole debugger gets locked randomly when the DB gets pegged.

当我的数据库速度非常慢时,我已经看到了这种行为,NHibernate试图在引擎盖下写入它,并且整个调试器在数据库被挂钩时被随机锁定。

#1


2  

I've seen stalling problems where the debugger is trying to evaluate the variables shown in the Auto/Local windows. If the evaluation is complicated then it can cause significant stalls.

我已经看到调试器试图评估自动/本地窗口中显示的变量的停滞问题。如果评估很复杂,那么它可能会导致严重的停顿。

You can turn the auto-evaluation off through Tools|Options and it does make a big difference.

您可以通过工具|选项关闭自动评估,它确实会产生很大的不同。

#2


2  

I have come across with this kind of behavior, though this is my first time.

我遇到过这种行为,虽然这是我的第一次。

I have got through this problem, by two ways

我通过两种方式解决了这个问题

  1. Your way of putting this attribute, [System.Diagnostics.DebuggerDisplay("Form1")]
  2. 你放置这个属性的方法,[System.Diagnostics.DebuggerDisplay(“Form1”)]

  3. Turning off Tools->Options->Debugging->General->Enable Property evaluation and other implicit function calls.
  4. 关闭工具 - >选项 - >调试 - >常规 - >启用属性评估和其他隐式函数调用。

I am still debugging my code but It seems to me that some of the Autos evaluation is failing (possibly throwing an exception), which is possibly crashing the debugger.

我仍在调试我的代码,但在我看来,一些Autos评估失败(可能抛出异常),这可能会使调试器崩溃。

Please let us know if this is also your case.

如果您也是这样,请告诉我们。

#3


1  

What sort of code are you debugging?

你在调试什么样的代码?

When you "step into" are you calling your own .NET code, or calling a native library, or an external assembly that you don't have the pdb files for? Either of these situations would cause the debugger to freeze while the external code was executing.

当你“步入”你是在调用自己的.NET代码,还是调用本机库,或者你没有pdb文件的外部程序集?这些情况中的任何一种都会导致调试器在外部代码执行时冻结。

#4


1  

If you debug multithreaded application you might be changing of thread. You can switch between Thread with the "Thread windows" while debugging to be able to see again where the debug yellow line is.

如果您调试多线程应用程序,您可能正在更改线程。您可以在调试时使用“Thread windows”在Thread之间切换,以便能够再次查看调试黄线所在的位置。

#5


0  

My psychic debugger says that you're missing symbols for something and that VS is hitting the network trying to look them up. Try setting your symbol path to something weird like C:\foo.

我的通灵调试器说你错过了某些东西的符号,VS正在试图查找它们。尝试将符号路径设置为奇怪的东西,如C:\ foo。

#6


0  

dead-lock seems likely in your case. Press the pause button and look at the threads view next time it happens.

你的情况似乎很可能是死锁。按下暂停按钮,下次发生时查看线程视图。

#7


0  

I have seen this type of behavior when my DB was being very slow, NHibernate is trying to write to it under the hood, and the whole debugger gets locked randomly when the DB gets pegged.

当我的数据库速度非常慢时,我已经看到了这种行为,NHibernate试图在引擎盖下写入它,并且整个调试器在数据库被挂钩时被随机锁定。