它沒有,它停止在你給出Debug + Break命令時任何代碼處於活動狀態。你可以在調試器的Call Stack窗口中看到。然而,你會打斷你自己執行代碼的機率很小,你的程序花費99%的時間等待Windows來告訴它發生了一些有趣的事情。這使得調用堆棧通常如下所示:
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x444 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x155 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x4a bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes
> WindowsFormsApplication1.exe!WindowsFormsApplication1.Program.Main() Line 16 + 0x1d bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6b bytes
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x6f bytes
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes
[Native to Managed Transition]
注意FPushMessageLoop()方法位於堆棧跟蹤之上。這是Windows GUI應用程序中着名的消息循環,它是接收Windows通知的應用程序。如果你還啓用了非託管調試,那麼你會看到更多,核心GetMessage()winapi函數是消息循環的重要組成部分。
請注意堆棧跟蹤中的>
標記。這就是你正在談論的代碼行。你看到它的原因是因爲它上面的代碼是.NET框架的一部分。如果您沒有安裝參考源,則您沒有源代碼。
所以調試器只是走棧,尋找任何相關的源代碼來顯示。並且不可避免地會在Program.cs中的Main()方法中執行Application.Run()調用。
在GUI應用程序中獲得有用的中斷需要設置斷點。
這是不幸的。另一個原因是我更喜歡從單元測試中進行調試。從單元測試中,我確信暫停按鈕會停在我寫的代碼上 - 而不是着名的循環。 – sapbucket
呃,不,這當然不能保證。它也可能在代碼被深埋在winapi或框架調用中時破壞。唯一的區別是,您可能認爲調試器選擇的源代碼文件與您更相關。這實際上只是這種情況,因爲單元測試不會在99%的時間內無所事事。所以,也許真正的問題是,使用Debug + Break All時,由於代碼並未執行,因此在使用它時沒有意義。當代碼陷入循環時,你只會真的需要它。 –