Skip to content
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

Don't await a DispatcherOperation #41

Open
randymarsh77 opened this issue Jan 14, 2019 · 0 comments
Open

Don't await a DispatcherOperation #41

randymarsh77 opened this issue Jan 14, 2019 · 0 comments
Labels
new analyzer Suggestion for a new analyzer to add

Comments

@randymarsh77
Copy link
Member

We never cloned the awaitable duck-typing interface of DispatcherOperation in our port of it to Mac. Writing code that awaits a DispatcherOperation will compile, and then crash at runtime when executed on Mac.

Furthermore, a common mechanism of obtaining a DispatcherOperation is from a call to DispatcherUtility.BeginInvokeIfNecessary, which will return null if the invoke is not necessary. This makes would-be usage somewhat a pit of failure.

Instead, either:

  • Use BeginInvoke(IfNecessary) and ignore the result if fire-and-forget is sufficient.
  • Use an explicit thread-switching mechanism if an AsyncMethodContext or AsyncActions context is available.
  • Use Invoke to synchronously execute code on the Dispatcher's context in a cross-platform compatible way.
@randymarsh77 randymarsh77 added the new analyzer Suggestion for a new analyzer to add label Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new analyzer Suggestion for a new analyzer to add
Development

No branches or pull requests

1 participant