CSharpFeeds - All your C# feeds in one place.

Sponsors

Monday, June 08, 2009

Multithreading: APM and options for waiting until work completes

by luisabreu via LA.NET [EN] on 6/8/2009 8:50:47 AM

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.


email it!bookmark it!digg it!

Original Post: Multithreading: APM and options for waiting until work completes

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us