我们有一个卡在 Windows 8 触摸设备上的 WPF 程序 (.net 3.5 sp1)。
我使用“托管堆栈资源管理器”来查看线程,在消除我们自己的线程后,这是唯一剩下的堆栈跟踪:
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)
我发现很少有其他类似问题的引用资料,都包括 Windows 8 和触摸设备,但没有解决方案。其他地方使用的.Net框架是4.0。
除了为这个问题写一个解决方法,还有什么真正的解决方案吗?
最佳答案
它看起来像我们在 WPF 手写笔逻辑中发现的竞争条件。尝试在 WPF 应用程序启动之前执行此代码:
(他们使用带有 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
{
}
}
关于WPF 应用程序卡在 Windows 8 触摸设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21752256/