6

Are there any standard tools, or recommended approaches for async tasks execution?

UPD I understand, how to use threads. I only need to know the recommended WPF way to block UI while performing async call, and how to update progress info.

Tom Dudfield
  • 3,047
  • 2
  • 24
  • 39
user536232
  • 645
  • 5
  • 17

4 Answers4

7

You can use several ways, for example:

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

akjoshi
  • 14,989
  • 13
  • 101
  • 119
Daniel Hilgarth
  • 166,158
  • 40
  • 312
  • 426
1

Have a look at below post, it describes a way to create an async delegate command(using BackgroundWorker). I have used this kind of command in our application and it works fine and at the same time it provides a consistent way of doing things asynchronously.

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

A similar implementation is also mentioned here - Asynchronous WPF Commands

Community
  • 1
  • 1
akjoshi
  • 14,989
  • 13
  • 101
  • 119
0

depends what you are trying to do async. e.g. calling a WCF service I'd use the build-in way, with the Completed pattern that does the marshalling for you. Normal Background work I'd use the BackgroundWorker as you again don't need to worry about the marshalling.

Martin Moser
  • 6,049
  • 1
  • 25
  • 39
0

In addition to standard threads. One thing to use are Async methods of many classes, that can do it. This includes web service requests, file read/write operations.

One thing to look at is Coroutines, used mainly by Caliburn.Micro . But its not standard way to do it.

Also .NET 4 adds Task class along with ParallelExtensions, that is capable to do some async programming easier. But its still clumsy, so .NET 5 adds async programing model, to make thigs even easier. But god knows when its going to be released.

Euphoric
  • 12,302
  • 1
  • 27
  • 41