我的代码陷入僵局。这是主线程的堆栈跟踪:
[Managed to Native Transition]
WindowsBase.dll!MS.Win32.UnsafeNativeMethods.GetMessageW(ref System.Windows.Interop.MSG msg, System.Runtime.InteropServices.HandleRef hWnd, int uMsgFilterMin, int uMsgFilterMax) + 0x14 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.GetMessage(ref System.Windows.Interop.MSG msg, System.IntPtr hwnd, int minMessage, int maxMessage) + 0x80 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x75 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x49 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x4b bytes
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) + 0x17 bytes
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x6f bytes
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x26 bytes
PresentationFramework.dll!System.Windows.Application.Run() + 0x1b bytes MainDashboard.exe!MainDashboard.App.Main() + 0x59 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]
我怎么知道我的代码的哪一部分负责。应用程序入口点是:
MainDashboard.exe!MainDashboard.App.Main() + 0x59 bytes C#
那是该堆栈跟踪中唯一来自我的代码的行。
尝试查看其他两个框架的调用堆栈将显示以下内容:
The current thread is not currently running code all the call stack is could not be obtained.
这是另一个工作线程的调用堆栈:
[Managed to Native Transition]
System.dll!Microsoft.Win32.SystemEvents.WindowThreadProc() + 0xaf 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]
这是最后一个线程的调用堆栈:
[Managed to Native Transition]
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.WaitForThreadExit() + 0x93 bytes Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunParkingWindowThread() + 0x253 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]
该应用已被挂起。它总共需要处理49,000条记录。它停止在3029。该应用程序此时未使用任何资源。任务管理器正在使用0%CPU来显示它。 UI是响应式的,但设计为始终响应式的。
同样,这不是确定性的。我的意思是,如果我重新启动该应用程序,它将卡在代码中的另一个位置,因此,没有一条记录会出现使整个系统崩溃的问题。
最佳答案
由于您现在在“输出”中注意到“第一次机会异常”,并且它们似乎杀死了您的线程,因此除了try/catch/log之外还有其他事情。
进一步使用VS/CLR的调试功能。转到DEBUG菜单,然后EXCEPTIONS然后找到一个(或所有,但我更喜欢一个一个地完成)您标识为抛出并杀死您的线程的异常,即InvalidOperationException并选中“已抛出”或“未处理”(取决于您想要什么以及您拥有的VS版本)。
现在,假设您勾选了“抛出”,则IDE会在尝试完全抛出这种类型的异常时自动中断/暂停程序。
..不仅会暂停程序,还会跳到那里,就好像您放置了一个断点一样。您将立即获得所有要检查的堆栈跟踪,变量,代码等。
但是,另一方面,如果您的应用程序以每秒数千的速率发送此类异常垃圾邮件,那仅仅是因为有人很懒,并且是否/有其他一些错误的论点,然后尝试/捕获了该异常,然后尝试依靠此异常被“抛出”将..很好..失败。在这种情况下,您可能想尝试使用“未处理的”刻度(如果您在IDE中完全看到它),但是当然它也有其自身的局限性。但是,如果您可以将IDE附加到失败的过程中,它们将是非常宝贵的工具。在未知行上Insta-break出现问题!
关于c# - 如何查找导致.NET方法导致工作人员停止的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19912623/