Itai Bar-Haim
Itai Bar-Haim

Reputation: 1674

WPF App hangs on Windows 8 touch devices

We have a WPF program (.net 3.5 sp1) that hangs on Windows 8 touch devices.

I used "Managed Stack Explorer" to see the threads and after eliminating our own threads this is the only stack trace left:

0. [Internal thisFrame, 'M-->U', MS.Win32.UnsafeNativeMethods::IntWaitForMultipleObjectsEx] (Source Unavailable)
1. MS.Win32.UnsafeNativeMethods.WaitForMultipleObjectsEx (Source Unavailable)
2. System.Windows.Threading.DispatcherSynchronizationContext.Wait (Source Unavailable)
3. System.Threading.SynchronizationContext.InvokeWaitMethodHelper (Source Unavailable)
4. System.Threading.WaitHandle.WaitOne (Source Unavailable)
5. System.Threading.WaitHandle.WaitOne (Source Unavailable)
6. System.Threading.WaitHandle.WaitOne (Source Unavailable)
7. System.Windows.Input.PenThreadWorker.WorkerGetTabletsInfo (Source Unavailable)
8. System.Windows.Input.TabletDeviceCollection.UpdateTablets (Source Unavailable)
9. System.Windows.Input.TabletDeviceCollection..ctor (Source Unavailable)
10. System.Windows.Input.StylusLogic.get_TabletDevices (Source Unavailable)
11. System.Windows.Input.StylusLogic.PreProcessInput (Source Unavailable)
12. System.Windows.Input.InputManager.ProcessStagingArea (Source Unavailable)
13. System.Windows.Input.InputManager.ProcessInput (Source Unavailable)
14. System.Windows.Input.InputProviderSite.ReportInput (Source Unavailable)
15. System.Windows.Interop.HwndMouseInputProvider.ReportInput (Source Unavailable)
16. System.Windows.Interop.HwndMouseInputProvider.PossiblyDeactivate (Source Unavailable)
17. System.Windows.Interop.HwndMouseInputProvider.Dispose (Source Unavailable)
18. System.Windows.Interop.HwndMouseInputProvider.FilterMessage (Source Unavailable)
19. System.Windows.Interop.HwndSource.InputFilterMessage (Source Unavailable)
20. MS.Win32.HwndWrapper.WndProc (Source Unavailable)
21. MS.Win32.HwndSubclass.DispatcherCallbackOperation (Source Unavailable)
22. System.Windows.Threading.ExceptionWrapper.InternalRealCall (Source Unavailable)
23. System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Source Unavailable)
24. System.Windows.Threading.Dispatcher.WrappedInvoke (Source Unavailable)
25. System.Windows.Threading.Dispatcher.InvokeImpl (Source Unavailable)
26. System.Windows.Threading.Dispatcher.Invoke (Source Unavailable)
27. MS.Win32.HwndSubclass.SubclassWndProc (Source Unavailable)
28. [Internal thisFrame, 'M-->U', MS.Win32.UnsafeNativeMethods::IntDestroyWindow] (Source Unavailable)
29. MS.Win32.HwndWrapper.DestroyWindow (Source Unavailable)
30. MS.Win32.HwndWrapper.Dispose (Source Unavailable)
31. MS.Win32.HwndWrapper.Dispose (Source Unavailable)
32. System.Windows.Interop.HwndSource.Dispose (Source Unavailable)
33. System.Windows.Interop.HwndSource.WeakEventDispatcherShutdown.OnShutdownFinished (Source Unavailable)
34. System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext (Source Unavailable)
35. System.Threading.ExecutionContext.runTryCode (Source Unavailable)
36. System.Threading.ExecutionContext.RunInternal (Source Unavailable)
37. System.Threading.ExecutionContext.Run (Source Unavailable)
38. System.Windows.Threading.Dispatcher.ShutdownImpl (Source Unavailable)
39. System.Windows.Threading.Dispatcher.PushFrameImpl (Source Unavailable)
40. System.Windows.Threading.Dispatcher.PushFrame (Source Unavailable)
41. System.Windows.Threading.Dispatcher.Run (Source Unavailable)
42. System.Windows.Application.RunDispatcher (Source Unavailable)
43. System.Windows.Application.RunInternal (Source Unavailable)
44. System.Windows.Application.Run (Source Unavailable)
45. System.Windows.Application.Run (Source Unavailable)
46. MyProgram.App.Main (Source Unavailable)

I found very few other references to similar issues, all include Windows 8 and a touch device, but there was no solution. The .Net framework used in other places was 4.0.

Except for writing a workaround for this issue, is there any real solution to it?

Upvotes: 5

Views: 1103

Answers (1)

Famos
Famos

Reputation: 261

It's look like race condition, what we found in WPF stylus logic. Try to execute this code before you WPF app started: (They use static constructor with getTablets.DoneEvent.WaitOne(); )

 private static void PreventPimcManagerDeadlock()
 {
     try
     {
         var presentationCoreAssembly = typeof(Timeline).Assembly;
         var unsafeNativeMethodsType = presentationCoreAssembly.GetType(
             "MS.Win32.Penimc.UnsafeNativeMethods", false, true);
         if (unsafeNativeMethodsType == null)
             return;

         var pimcManagerField = unsafeNativeMethodsType.GetField(
             "_pimcManager", BindingFlags.NonPublic | BindingFlags.Static);
         if (pimcManagerField == null)
             return;

         pimcManagerField.GetValue(null);
     }
     catch
     {
     }
 }

Upvotes: 2

Related Questions