An exception occurs when you press a button on the touch screen using the stylus or finger in the WPF application

I have a WPF application with an initial window that displays as a Splashscreen on startup. There is a background thread during startup, and we can cancel this thread by clicking the button in the splash screen. This all works great when you use the mouse and press a button to cancel. However, if I use the touch screen to click on this button, sometimes it happens that the application crashes and the next one is a stack trace. An application is a 64-bit target running on Windows 7 64bit.

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 

Has anyone encountered this problem before?

+4
source share
2 answers

Are you using an Elo touchscreen? I have a similar crash in StylusLogic OnDispatcherShutdown with Elo touchscreen. I solved this by disabling RealTimeStylus for wpf ( Disable RealTimeStylus for WPF applications ). It seems to me that the event is processed twice (in the display driver and wpf stylus), but on the wpf Stylus handler the window is already destroyed. Also, a slight delay before calling a closed window worked for me.

+5
source

Based on Luz De Gan's answer, I found that delaying window closure works best without disabling RealTimeStylus.

In the undo event handler, use this to delay closing the window:

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

It must be DispatcherPriority.Input to ensure that closure occurs after touch input events have been processed.

+2
source

All Articles