views:

919

answers:

2

I have thread exception handler which saves the exception stack trace and should close the application. I call Applicatoin.Exit, but that only closes the window, living the app running windowless.

I know, that this usually happens because some background threads are still running. I attached windbg to the windowless process and there seem to be only two managed threads, one of which looks like the gc finalizer thread, the second looks like a message pump??? Anyone understands this?

Is there a difference between calling Application.Exit and user closing the main window?

0:005> !threads
ThreadCount: 2
UnstartedThread: 0
BackgroundThread: 1
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
                                      PreEmptive   GC Alloc           Lock
       ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception
   0    1  284 002e9668      6020 Enabled  021a7268:021a7fe8 002e4c68     0 STA
   2    2  d48 002f9890      b220 Enabled  00000000:00000000 002e4c68     0 MTA (Finalizer)
0:001> ~0 s
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\MSCTF.dll - 
eax=02162530 ebx=002e9668 ecx=02162530 edx=02162530 esi=0019ef9c edi=0019ee3c
eip=77589a94 esp=0019edcc ebp=0019ede8 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
ntdll!KiFastSystemCallRet:
77589a94 c3              ret
0:000> !clrstack
OS Thread Id: 0x284 (0)
ESP       EIP     
0019ef24 77589a94 [ComPlusMethodFrameGeneric: 0019ef24] MS.Win32.UnsafeNativeMethods+ITfMessagePump.GetMessageW(System.Windows.Interop.MSG ByRef, Int32, Int32, Int32, Boolean ByRef)
0019ef44 56d61937 System.Windows.Threading.Dispatcher.GetMessage(System.Windows.Interop.MSG ByRef, IntPtr, Int32, Int32)
0019ef90 56d617e3 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
0019efe0 56d616c7 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
0019effc 56d6162d System.Windows.Threading.Dispatcher.Run()
0019f008 5533ddb0 System.Windows.Application.RunInternal(System.Windows.Window)
0019f034 5533dbe5 System.Windows.Application.Run(System.Windows.Window)
0019f044 5533d836 System.Windows.Application.Run()
0019f04c 01ea00ad UI.App.Main()
0019f268 79e7c74b [GCFrame: 0019f268] 

A: 

Is it possible that a finaliser is hanging and somehow the other main thread is waiting for the finaliser to finish?

Quibblesome
+8  A: 

I worked it out. Instead of calling System.Windows.Forms.Application.Exit() I should have called System.Windows.Application.Shutdown(). The message pump thread belongs to wpf, you can see it from the stack trace of that thread.

In other words, System.Windows.Forms.Application.Exit() will not close WPF message pumps.

luntain
Did you check if it still exists in your task manager services section?
Samiksha