Easier programming asynchronous calls

Asynchronous calls can improve scalability, however, it's always more difficult for us to do programming jobs under an asynchronous calling manner. The main reason is, asynchronous calls need callbacks everywhere, thus local variables and parameters in the current scope can not be easily passed through (ofcause you can use lambdas and anonymous methods, but they can't solve all the problems either). Moreover, when you need to perform many tasks which should be completed in an sequential order, for example, the latter asynchronous call may need to use the result of a previous one, it'll be even harder to implement, and if you've done it, the code may look terribly wired and not intuitive enough for understanding and maintaining.

For these reasons, programming asynchronous calls in synchronous manner is needed. I've looked through some articles on the internet and I think some resources listed here may worth you to have a look at:

1. Jeffrey Richter's Power Threading library.
http://www.wintellect.com/CS/blogs/jeffreyr/archive/2008/12/04/7380.aspx#7383

In the implementation for this library Jeff has used the C# 2.0 language's great 'iterator' feature (yield return) to achieve it. By following his examples you can easily program asynchronous calls in an synchronous manner and at the same time, you can still take the advantage of various C# features like foreach/lock/try..catch, and so on. Also, this awesome library has an version for Silverlight.

2. Synchronous Web Service Calls with Silverlight 2: Dispelling the async-only myth
http://www.codeproject.com/KB/silverlight/SynchronousSilverlight.aspx

This great article by Daniel Vaughan is for calling WCF Services in Silverlight, in an synchronous programming style, it's also easy to understand and the idea is explained in detail.

posted on 2009-01-18 11:45  NeilChen  阅读(1948)  评论(2编辑  收藏  举报

导航