8000 Catch and rethrow the exception in StylusPlugIn by lindexi · Pull Request #945 · dotnet/wpf · GitHub
[go: up one dir, main page]

Skip to content

Catch and rethrow the exception in StylusPlugIn #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit 8000
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change comment
  • Loading branch information
lindexi committed Jun 21, 2019
commit 90434f7aa359d228742c9fd38b84841cc9b59eb1
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,23 @@ internal void RawStylusInput(RawStylusInput rawStylusInput)
}
catch (Exception e)
{
// this code running in Stylus Input thread
// and the developer will re-write the method with their code
// If they throw any exceptions careless, that the thread will break and the application crash and the application will stop responding touch
// But we should not ignore the exception, and we can re-throw it in the main thread
// Why we should use InvokeAsync to replace Invoke? Because maybe some friend will make the main thread wait for the code above
// This code is running on the Stylus Input thread
// and has the chance to call out into app code.
// If the app code throws an exception that is not caught,
// then the app will crash
// and the application will stop responding the touch.
// We don't want to ignore all exceptions,
// so we catch the exception and
// dispatch it to the main thread,
// allowing developers to handle it inside the handler
// for the `Application.DispatcherUnhandledException` event.
_pic.Element.Dispatcher.InvokeAsync(() =>
{
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(e).Throw();
},
// Why we should use `Send` priority? Maybe the main thread is busy that the developer can not find the exception timely
// Why we should use `Send` priority?
// Maybe the main thread is busy
// that the developer can not find the exception timely
DispatcherPriority.Send);
}
}
Expand Down
0