Technology

Async/Await best practices

Posted on

Here are some best practices on async/await programing model based on reading from: Async/Await – Best Practices in Asynchronous Programming TPL and async/await Best Practices for the Busy Developer Use ‘async Task’ or ‘async Task<T>’ instead of ‘async void’. Why? Primarily because of error-handling semantics. When using ‘async void’, any exception thrown will be raised directly on the SynchronizationContext that was active when the async void method started. When using ‘async Task’, exception is captured and plated on the Task object. The exception is asynchronous event handlers, which must regturn void (ex: ICommand.Execute implementations)

Async code works best if it goes all the way from bottom up (or top down). That means that you shouldn’t mix synchronous and asynchronous […]

Technology

WPF UI Responsiveness

Posted on

All window objects are associated with the dispatcher where it has been created. Golden rules: Any UI element must be touched from the same UI thread that created it Don’t block the UI thread How to execute slow work then? In summary, perform slow work asynchronously update the UI using the Dispatcher.BeginInvoke Example:

  DispatcherPriority list …. Windows forms way: