我有一个控制台应用程序有时会在退出时挂起。也许千分之一,它会挂起。当它挂起时,剩下一个线程,它消耗100%的CPU。
如果我查看ProcessExplorer中的进程,当我进入ProcessExplorer的“Threads”选项卡时,我的进程正常退出。
查看WinDbg中的挂起进程,调用堆栈如下所示:
. 0 Id: 830.d00 Suspend: 1 Teb: 000007ff`fffde000 Unfrozen
Start: MyHost!COM+_Entry_Point <PERF> (MyHost+0x71ee) (00000000`002571ee)
Priority: 0 Priority class: 16384 Affinity: ff
Child-SP RetAddr Call Site
00000000`003ddc50 000007fe`ec3f7646 System_EnterpriseServices_Wrapper_7feec3f0000!CRT_INIT+0x65
00000000`003ddc90 000007fe`f91a4485 System_EnterpriseServices_Wrapper_7feec3f0000!DllMainCRTStartup+0x126
00000000`003ddcd0 000007fe`f93f3281 mscoreei!CorDllMain+0x1f5
00000000`003ddd50 000007fe`f93f32cf MSCOREE!ShellShim__CorDllMain+0xe1
00000000`003ddd80 00000000`77a54371 MSCOREE!CorDllMain_Exported+0x37
00000000`003dddb0 00000000`77a54180 ntdll!LdrShutdownProcess+0x1db
00000000`003dded0 000007fe`f91926d2 ntdll!RtlExitUserProcess+0x90
00000000`003ddf00 000007fe`f9192848 mscoreei!RuntimeDesc::ShutdownAllActiveRuntimes+0x294
00000000`003de1f0 000007fe`f89cc919 mscoreei!CLRRuntimeHostInternalImpl::ShutdownAllRuntimesThenExit+0x14
00000000`003de220 000007fe`f897ef51 clr!EEPolicy::ExitProcessViaShim+0x69
00000000`003de270 000007fe`f8976776 clr!SafeExitProcess+0x9d
00000000`003de4e0 000007fe`f8d56971 clr!EEPolicy::GetFinalAction+0x9a
00000000`003de510 000007fe`f7b5f93b clr!SystemNative::Exit+0x52
00000000`003de560 000007fe`99142057 mscorlib_ni+0xcaf93b
00000000`003de630 000007fe`f87f07f3 0x7fe`99142057
00000000`003de900 000007fe`f87f02fe clr!CallDescrWorkerInternal+0x83
00000000`003de940 000007fe`f87f03c7 clr!CallDescrWorkerWithHandler+0x4a
00000000`003de980 000007fe`f892cdf0 clr!MethodDescCallSite::CallTargetWorker+0x2e6
00000000`003deb30 000007fe`f892d54e clr!RunMain+0x1e7
00000000`003ded00 000007fe`f892d448 clr!Assembly::ExecuteMainMethod+0xb6
00000000`003deff0 000007fe`f892cfc2 clr!SystemDomain::ExecuteMainMethod+0x45e
00000000`003df5b0 000007fe`f892cf0e clr!ExecuteEXE+0x3f
00000000`003df620 000007fe`f8929914 clr!CorExeMainInternal+0xae
00000000`003df6b0 000007fe`f91874e5 clr!CorExeMain+0x14
00000000`003df6f0 000007fe`f93e5b21 mscoreei!CorExeMain+0xe0
00000000`003df740 00000000`7782652d MSCOREE!CorExeMain_Exported+0x57
00000000`003df770 00000000`77a5c521 KERNEL32!BaseThreadInitThunk+0xd
00000000`003df7a0 00000000`00000000 ntdll!RtlUserThreadStart+0x1d
我怎样才能弄清楚这是做什么的?
答案 0 :(得分:0)
此挂起是由WorkflowApplication完成之前退出应用程序引起的。我们在收到“已完成”事件后退出,但我们需要等待已完成和已卸载。
很难追踪,因为挂起不在我们的代码中,而且不在Workflow Foundation代码中。这是一个循环,等待计数器递减到零,但没有什么会减少计数器。我们让微软查看进程转储,他们可以看到为什么它被挂起但无法找到导致挂起的事件序列,因为它只挂了1000次中的1次,当我们插入检测时,它不会挂起。
我们终于通过在返回之前加上延迟来找到原因,并且我们意识到我们得到的是Unload事件,我们没有看到没有延迟。