【发布时间】:2010-11-21 05:58:40
【问题描述】:
我有一个多线程 WPF 应用程序在运行超过 8 小时后使用 > 600 个线程。除了大约 10 个线程之外,所有线程都有一个与此非常相似的堆栈跟踪:
堆栈跟踪 1:
ntkrnlpa.exe!NtInitialUserProcessBuffer+0x7b ntkrnlpa.exe!MiAddWorkingSetPage+0x174 ntkrnlpa.exe!MiAddWsleHash+0x12a ntkrnlpa.exe!PopSystemButtonHandler+0x141 ntkrnlpa.exe!KiInterruptTemplate+0x62 ntdll.dll!KiFastSystemCallRet ntdll.dll!ZwWaitForMultipleObjects+0xc KERNEL32.dll!WaitForMultipleObjectsEx+0x12c mscorwks.dll!WaitForMultipleObjectsEx_SO_TOLERANT+0x6f mscorwks.dll!Thread::DoAppropriateAptStateWait+0x3c mscorwks.dll!Thread::DoAppropriateWaitWorker+0x13c mscorwks.dll!Thread::DoAppropriateWait+0x40 mscorwks.dll!WaitHandleNative::CorWaitOneNative+0x156 mscorlib.ni.dll+0x1f68af mscorlib.ni.dll+0x1caa17 WindowsBase.ni.dll+0x24ac34 WindowsBase.ni.dll+0x2aeb1e WindowsBase.ni.dll+0x9445d WindowsBase.ni.dll+0x9267f mscorwks.dll!JITutil_IsInstanceOfAny+0x106 mscorlib.ni.dll+0x1e842f mscorwks.dll!CallDescrWorker+0x33 mscorwks.dll!CallDescrWorkerWithHandler+0xa3 mscorwks.dll!MethodDesc::CallDescr+0x19c mscorwks.dll!MethodDesc::CallTargetWorker+0x1f mscorwks.dll!MethodDescCallSite::Call+0x1a mscorwks.dll!ExecuteCodeWithGuaranteedCleanupHelper+0x9f mscorwks.dll!ReflectionInvocation::ExecuteCodeWithGuaranteedCleanup+0x10f mscorlib.ni.dll+0x235677 mscorlib.ni.dll+0x2202a5 mscorlib.ni.dll+0x1e839b mscorwks.dll!CallDescrWorker+0x33 mscorwks.dll!CallDescrWorkerWithHandler+0xa3 mscorwks.dll!DispatchCallBody+0x1e mscorwks.dll!DispatchCallDebuggerWrapper+0x3d mscorwks.dll!DispatchCallNoEH+0x51 mscorwks.dll!AddTimerCallback_Worker+0x66 mscorwks.dll!Thread::DoADCallBack+0x32a mscorwks.dll!Thread::ShouldChangeAbortToUnload+0xe3 mscorwks.dll!Thread::ShouldChangeAbortToUnload+0x30a mscorwks.dll!Thread::ShouldChangeAbortToUnload+0x33e mscorwks.dll!ManagedThreadBase::ThreadPool+0x13 mscorwks.dll!AddTimerCallbackEx+0x83 mscorwks.dll!AddTimerCallback+0x10 mscorwks.dll!ThreadpoolMgr::AsyncTimerCallbackCompletion+0x64 mscorwks.dll!UnManagedPerAppDomainTPCount::DispatchWorkItem+0x9a mscorwks.dll!ThreadpoolMgr::ExecuteWorkRequest+0xaf mscorwks.dll!ThreadpoolMgr::WorkerThreadStart+0x20b mscorwks.dll!Thread::intermediateThreadProc+0x49 KERNEL32.dll!BaseThreadStart+0x37
堆栈跟踪 2:
ntkrnlpa.exe!NtInitialUserProcessBuffer+0x7b ntkrnlpa.exe!MiAddWorkingSetPage+0x174 ntkrnlpa.exe!MiAddWsleHash+0x12a ntkrnlpa.exe!PopSystemButtonHandler+0x141 ntkrnlpa.exe!KiInterruptTemplate+0x62 ntdll.dll!KiFastSystemCallRet ntdll.dll!ZwWaitForMultipleObjects+0xc KERNEL32.dll!WaitForMultipleObjectsEx+0x12c mscorwks.dll!WaitForMultipleObjectsEx_SO_TOLERANT+0x6f mscorwks.dll!Thread::DoAppropriateAptStateWait+0x3c mscorwks.dll!Thread::DoAppropriateWaitWorker+0x13c mscorwks.dll!Thread::DoAppropriateWait+0x40 mscorwks.dll!WaitHandleNative::CorWaitOneNative+0x156 mscorlib.ni.dll+0x1f68af mscorlib.ni.dll+0x1caa17 WindowsBase.ni.dll+0x24ac34 WindowsBase.ni.dll+0x2aeb1e WindowsBase.ni.dll+0x9445d WindowsBase.ni.dll+0x9267f mscorwks.dll!JITutil_IsInstanceOfAny+0x106 mscorlib.ni.dll+0x1e842f mscorwks.dll!CallDescrWorker+0x33 mscorwks.dll!CallDescrWorkerWithHandler+0xa3 mscorwks.dll!MethodDesc::CallDescr+0x19c mscorwks.dll!MethodDesc::CallTargetWorker+0x1f mscorwks.dll!MethodDescCallSite::Call+0x1a mscorwks.dll!ExecuteCodeWithGuaranteedCleanupHelper+0x9f mscorwks.dll!ReflectionInvocation::ExecuteCodeWithGuaranteedCleanup+0x10f mscorlib.ni.dll+0x235677 mscorlib.ni.dll+0x2202a5 mscorlib.ni.dll+0x1e839b mscorwks.dll!CallDescrWorker+0x33 mscorwks.dll!CallDescrWorkerWithHandler+0xa3 mscorwks.dll!DispatchCallBody+0x1e mscorwks.dll!DispatchCallDebuggerWrapper+0x3d mscorwks.dll!DispatchCallNoEH+0x51 mscorwks.dll!AddTimerCallback_Worker+0x66 mscorwks.dll!Thread::DoADCallBack+0x32a mscorwks.dll!Thread::ShouldChangeAbortToUnload+0xe3 mscorwks.dll!Thread::ShouldChangeAbortToUnload+0x30a mscorwks.dll!Thread::ShouldChangeAbortToUnload+0x33e mscorwks.dll!ManagedThreadBase::ThreadPool+0x13 mscorwks.dll!AddTimerCallbackEx+0x83 mscorwks.dll!AddTimerCallback+0x10 mscorwks.dll!ThreadpoolMgr::AsyncTimerCallbackCompletion+0x64 mscorwks.dll!UnManagedPerAppDomainTPCount::DispatchWorkItem+0x9a mscorwks.dll!ThreadpoolMgr::ExecuteWorkRequest+0xaf mscorwks.dll!ThreadpoolMgr::WorkerThreadStart+0x20b mscorwks.dll!Thread::intermediateThreadProc+0x49 KERNEL32.dll!BaseThreadStart+0x37
应用程序使用 System.Threading.Timer 定期轮询来自使用 WCF 客户端代理的多个 Web 服务的数据,并且在任何给定时间,可能会同时发出大约 20 个此类请求。对 Web 服务的每次调用都会实例化一个新的代理实例,但当收到来自 Web 服务的响应时,客户端总是关闭。
应用程序还使用 GIS 的位图进行操作,这也是定期进行的。除了本地使用 Timer 类来定期轮询数据之外,我没有在代码中显式创建线程。 GIS 确实 使用 BackgroundWorker,但它们确实限制了线程数。
任何人都知道是什么产生了这些新线程以及为什么它们没有被释放?
TIA。
【问题讨论】:
标签: wpf multithreading