How many Asyncronous development models are in .NET?

I study asynchronous programming using C #, and I usually use BeginInvoke , but I am not very sure about other methods of creating an asynchronous application.

I asked a question about this, see the link below for more details:

How to return T value from BeginInvoke?

In the above link, Gravell said that there are four asynchronous development models.

There are at least 4, then - a regular callback (not APM, non-EAP) is also not unusual

But Overflow said there are three:

There are 3 models of asynchronous development in .NET.

  • APM - ( BeginXXX / EndXXX ), which you use here when the work on long work is completed, it refers to your code in the EndXXX method

  • EAP Event based. In this model, when long work is completed, an event occurs informing your code.

  • TPL New in .NET 4, this is a task-based version. It is most similar to synchronous programming on client code using a free interface. His calls to your code use ContinueWith .

Can anybody help me?

I searched google.com many times, but they actually use BeginInvoke most. thank you for your help.

+7
source share
3 answers

Thread.Start - Brutal

delegate.BeginInvoke/EndInvoke - the "old" standard

ThreadPool.QueueUserWorkItem - smart

TaskFactory.StartNew is the only way to do it right (according to the Patterns of parallel programming book | I recommend that you read it first to disambiguate)

+3
source

Of course, it will be useful to know the methods described by Mikant for asynchronous development. I just wanted to give you a head, although C # 5.0 is completely redefining how the language relates to async. This will be his main theme, along with the introduction of two new keywords, async and expectations. You simply call waiting in a long-running task and run the task and return control to the calling method. Once the task is completed, it will continue to work with the rest of the code.

Here's a great video for complete usage and explanation information. He not only describes the old way of performing asynchronous operations, but also a complete overview of the new style. This makes writing asynchronous applications finer and more readable with natural flow.

This is the future of C # asynchronous behavior that is worth exploring.

http://channel9.msdn.com/events/PDC/PDC10/FT09/

+1
source

There are many things that can be caught in terms of asynchronous development.


Firstly, you can execute the code in the background thread. I recently updated my blog post , contrasting several common approaches to running code in the background. Here is a list so that from the most desired to the smallest:

  • Task (as used by async / await).
  • Task (as used by the parallel task library).
  • BackgroundWorker .
  • Delegate.BeginInvoke .
  • ThreadPool.QueueUserWorkItem .
  • Thread

On the other hand, you might want to imagine an asynchronous operation (which may or may not be the actual execution of the code in the background thread). In this case, there are several approaches for which the smallest is most desirable:

(As a side note, BackgroundWorker is EAP, and Delegate.BeginInvoke is APM).


On the other hand, you could mean asynchronous programming as a whole, which could be construed as a reactive approach. In this case, I know only two approaches:

However, you can make sure that any event-driven program reacts to some extent, so just handling the user interface events is a (simple) form of "asynchronous programming."


In addition, these are only general models. Any platform or library can add more. Here are some of my legs:

  • The Socket class has a special APM form that can be used to minimize memory allocation. It is very similar to APM, but does not match the pattern.
  • WinRT runtime (included with Windows 8) has its own representations of asynchronous operations ( IAsyncOperation<TResult> and IAsyncInfo ).
  • Windows Phone has special background agent support, which allows you to run code in the background, even if your application is not currently running.
+1
source

All Articles