Multithreading: APM and options for waiting until work completes

Published Mon, Jun 8 2009 9:50

In the last post, we’ve started looking at oldest asynchronous pattern of the .NET framework: the APM model. Today, we’re going to list the available options for waiting to the completion of an asynchronous operation started through a framework that implements APM pattern.

After kicking off an asynchronous operation, we have four available options:

  • we can block the thread until work is completed by calling the EndXXX method directly. This is a good approach when we have a couple of extra things to do and, after that, we really need to wait until the asynchronous operation completes;
  • we can wait on the IAsyncResult’s WaitHandle (AsyncWaitHandle property) until the work that is being executed in parallel ends;
  • we can poll the IAsyncResult’s IsCompleted property. This is also a good option when we want to perform other tasks while the asynchronous operation is running;
  • we can pass a callback (WaitCallback parameter passed to the BeginXXX method) that is to be called when the operation completes. This is a good option when we don’t need to block the “main” thread until the operation completes and relies on a “continuation passing” style, where a closure is executed when the async operation ends.

As you can see, the APM model gives us several options  and we’ll take a detailed look at each in the next posts. Keep tuned for more.

Filed under: ,

Comments

# 9eFish said on Monday, June 08, 2009 9:20 AM

9efish.感谢你的文章 - Trackback from 9eFish

# LA.NET [EN] said on Tuesday, June 09, 2009 4:07 AM

As we’ve seen, one of the available options is blocking the thread by calling the EndXXX method directly

# ASPInsiders said on Tuesday, June 09, 2009 4:28 AM

As we’ve seen, one of the available options is blocking the thread by calling the EndXXX method directly.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover