I have a WPF application that hosts a Win32 modeless form. Everything runs smoothly until I connect or disconnect the VNC to the machine. Then lock the application: it does not redraw anything else, does not respond to user interaction. I looked at the stack trace using WinDbg:
0012f03c 792b6865 System.Threading.WaitHandle.WaitOne(Int32, Boolean)
0012f050 7b6f1a4f System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle)
0012f064 7ba2d68b System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean)
0012f104 7b6f33ac System.Windows.Forms.Control.Invoke(System.Delegate, System.Object[])
0012f138 7b920bd7 System.Windows.Forms.WindowsFormsSynchronizationContext.Send(System.Threading.SendOrPostCallback, System.Object)
0012f150 7a92ed62 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo.Invoke(Boolean, System.Object[])
0012f184 7a92dc8f Microsoft.Win32.SystemEvents.RaiseEvent(Boolean, System.Object, System.Object[])
0012f1d0 7a92daec Microsoft.Win32.SystemEvents.OnDisplaySettingsChanging()
0012f1e0 7a574c9f Microsoft.Win32.SystemEvents.WindowProc(IntPtr, Int32, IntPtr, IntPtr)
0012f1e4 003c20dc [InlinedCallFrame: 0012f1e4]
0012f3a8 57843a57 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
0012f3f8 57843129 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
0012f404 578430cc System.Windows.Threading.Dispatcher.Run()
0012f410 55bed46e System.Windows.Application.RunDispatcher(System.Object)
0012f41c 55bec76f System.Windows.Application.RunInternal(System.Windows.Window)
0012f440 55bd3aa6 System.Windows.Application.Run(System.Windows.Window)
0012f450 55bd3a69 System.Windows.Application.Run()
Apparently, the VNC attach / detach raises an event OnDisplaySettingsChanging, which, in turn, tries to raise some kind of event with the help System.Windows.Forms.Control.Invokethat sends the message to the main thread and then waits for a response. But since this all happens in the main thread, the message loop never receives the message, and the wait never returns.
, EnableSystemEventsThreadAffinityCompatibility ( Control.Invoke), .
- - ?
- , SystemEvents Control.Invoke, (STA) ( , )?
: :
- (, res) VNC? → .
- VNC ( hte latest)? → 1.0.9.5.
- WPF, Win32 contorls? → WPF WinForms.