What is the recommended way to perform asynchronous tasks in WPF?

Are there standard tools or recommended approaches for performing asynchronous tasks?

UPD I understand how to use streams. I only need to know the recommended WPF method for blocking the user interface when making an asynchronous call and how to update the progress information.

+6
source share
4 answers

You can use several methods, for example:

And since .NET 4, the preferred way is to use Tasks .

+7
source

Take a look at the following publication, which describes how to create an async delegate command (using BackgroundWorker ). I used this command in our application and it works great and at the same time provides a consistent way to do asynchronously.

Asynchronous delegate command for your WPF MVVM applications - AsyncDelegateCommand http://amazedsaint.blogspot.com/2010/10/asynchronous-delegate-command-for-your.html

A similar implementation is also mentioned here - Asynchronous WPF Commands

+1
source

depends on what you are trying to do async. for example, when calling the WCF service, I would use the built-in method, with the Completed template, which does the sorting for you. Normal background work I would use BackgroundWorker, since again you don't have to worry about sorting.

0
source

In addition to standard streams. One thing to use is the Async methods of many classes that can do this. This includes web service requests, file read / write operations.

One thing to look out for is the Coroutines, mainly used by Caliburn.Micro . But this is not a standard way to do this.

In addition, .NET 4 adds the Task class along with ParallelExtensions, which can simplify some asynchronous programming. But its still awkward, so .NET 5 adds an asynchronous programming model to make tigers even easier. But God knows when he will be released.

0
source

All Articles