我们有一个挂在Windows 8触控设备上的WPF程序(.net 3.5 sp1)。
我使用“Managed Stack Explorer”查看线程,在删除我们自己的线程后,这是唯一剩下的堆栈跟踪:
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。
除了为此问题编写解决方法之外,还有任何真正的解决方案吗?
答案 0 :(得分:2)
它看起来像竞争条件,我们在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
{
}
}