使用手写笔或WPF应用程序中的手指按下TouchScreen上的按钮时发生异常

时间:2013-01-31 21:55:09

标签: c# wpf stylus-pen

我有一个WPF应用程序,其初始窗口在启动时显示为Splashscreen。在Startup期间有一个后台线程,我们可以通过单击splashscreen中的按钮取消该线程。 使用鼠标并单击按钮取消时,一切正常。但是,如果我使用触摸屏点击此按钮,则偶尔应用程序崩溃,然后是堆栈跟踪。该应用程序是在Windows 7 64位上运行的64位目标。

Severity:
Fatal


Stack Trace:
Exception 0
Message: Object reference not set to an instance of an object.

StackTrace:

at MS.Internal.PointUtil.TryClientToRoot(Point point, PresentationSource presentationSource, Boolean throwOnError, Boolean& success)
at System.Windows.Input.StylusDevice.GetPosition(IInputElement relativeTo)
at System.Windows.Input.StylusDevice.ChangeStylusOver(IInputElement stylusOver)
at System.Windows.Input.StylusLogic.PreProcessInput(Object sender, PreProcessInputEventArgs e)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.PossiblyDeactivate(IntPtr hwndCapture, Boolean stillActiveIfOverSelf)
at System.Windows.Interop.HwndMouseInputProvider.Dispose()
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

FromSubsystem:
PresentationCore
Help Link:
Not specified

之前有没有人遇到过这个问题?

2 个答案:

答案 0 :(得分:5)

您使用的是Elo触摸屏吗?我在StylusLogic OnDispatcherShutdown中使用Elo触摸显示器发生了类似的崩溃。我解决了它,禁用了RealpSluslus for wpf(Disable the RealTimeStylus for WPF Applications)。它接触到我,事件被处理两次(在显示驱动程序和wpf手写笔中),但在wpf Stylus处理程序上,窗口已被销毁。在调用关闭窗口之前还有一点延迟对我有用。

答案 1 :(得分:2)

基于Luz De Gan的回答,我发现延迟关闭窗口效果最好而不必禁用RealTimeStylus。

在取消事件处理程序中,使用它来延迟关闭窗口:

Dispatcher.InvokeAsync(this.Close, DispatcherPriority.Input);

它必须是DispatcherPriority.Input才能确保在处理完触摸输入事件后发生关闭。