Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:01:02+00:00 2026-06-11T23:01:02+00:00

Imagine a WPF code-behind event handler: <Button Click=OnButtonClick /> In C# 4 you would

  • 0

Imagine a WPF code-behind event handler:

<Button Click="OnButtonClick" />

In C# 4 you would declare your handler as:

private void OnButtonClick(object sender, RoutedEventArgs e) { ... }

In C# 5 you can declare an async handler

private async void OnButtonClick(object sender, RoutedEventArgs e) { ... }

So what is WPF doing with this? A few minutes of searching about didn’t turn anything up.

It seems that it’s possible to perform UI updates after await statements. Does this imply that the task is continued on the Dispatcher thread?

If the Task raised an error, would it be raised through the WPF Dispatcher, or only via the TaskScheduler?

Are there any other interesting aspects to this that might be nice to understand?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:01:03+00:00Added an answer on June 11, 2026 at 11:01 pm

    You may find my async/await intro helpful.

    An async method is re-written by the compiler to support the await operator. Every async method starts out synchronous (in this case, on the UI thread) until it awaits some operation (that is not already completed).

    By default, the context is saved, and when the operation completes, the rest of the method is scheduled to execute in that context. The “context” here is SynchronizationContext.Current unless it is null, in which case it is TaskScheduler.Current. As Drew pointed out, WPF provides a DispatcherSynchronizationContext which is tied to the WPF Dispatcher.

    Regarding error handling:

    When you await a Task inside a WPF async void event handler, the error handling goes like this:

    • The Task completes with an error. The exception is wrapped into an AggregateException, like all Task errors.
    • The await operator sees that the Task completed with an error. It unwraps the original exception and re-throws it, preserving the original stack trace.
    • The async void method builder catches the exception escaping from an async void method and passes it to the SynchronizationContext that was active when the async void method started executing (in this case, the same WPF context).
    • The exception is raised (with the original stack trace, and without any annoying AggregateException wrapping) on the Dispatcher.

    This is rather convoluted, but the intent is to have exceptions raised from async event handlers be practically the same as exceptions raised from regular event handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine a simple scenario with a WPF window containing a button and some clear
I have a newbie WPF question. Imagine my user control has a namespace declaration
Imagine you have two views with code like the following: controller_a/a.html.erb <%= content_tag(:div) do
Imagine you have class A which has code which runs as method M. And
I have a databound object within a WPF control that is 'previewing' a mutlipage
Imagine a document window in a MDI application which contains a child WPF window,
I am designing a WPF user control which contains other user controls (imagine a
I am using following code in WPF to display image in webcam usingEmguCv library
I'm attempting to perform some simple panning on a WPF Canvas object with its
I have a really strange problem with WPF. A simple window with a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.