Exception occurs while pressing a button on TouchScreen using a Stylus or a finger in a WPF app

StackOverflow https://stackoverflow.com/questions/14635862

  •  06-03-2022
  •  | 
  •  

문제

I have WPF app with an initial window which shows up as Splashscreen at Startup. During the Startup there is a background thread and we can cancel the this thread by clicking the button in splashscreen. This all works fine while using mouse and clicking the button to cancel. However if I use the touchscreen to click on this button then occasionaly the app crashes and following is the stack trace. The app is a 64bit 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?

도움이 되었습니까?

해결책

Are you using Elo touch screen? I have a similar crash in StylusLogic OnDispatcherShutdown with Elo touch display. I have solved it, with disabling the RealTimeStylus for wpf (Disable the RealTimeStylus for WPF Applications). It seams to me, that the event is handled twice (in display driver and wpf stylus), but on the wpf Stylus handler the window is already destroyed. Also a little delay before calling close window has worked for me.

다른 팁

Based on Luz De Gan's answer, I found that delaying the closing of the window works the best without having to disable the RealTimeStylus.

In your cancel event handler, use this to delay the closing of the window:

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

It needs to be DispatcherPriority.Input in order to ensure that the closing happens after the touch input events have been processed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top