Posted By: Charles | Dec 3rd, 2008 @ 5:52 PM | 92,369 Views | 21 Comments
Jeffrey Richter’s Power Threading Library contains his AsyncEnumerator class which uses C# iterators to allow developers to perform asynchronous operations via an easy to use synchronous programming model. For those of you who can remember our conversations on CCR from years back, the use of iterators in this concurrent context is at the core of CCR's implementation of asynchronous processing. The power of iterators in C# enables all of this. The CCR team was in fact the first to employ an asynchronous programming model based on C# iterators, which was a very novel use of the new feature in C# 2.0. This doesn't take away from Jeff's current excellent async implemenation (not at all - Jeff has made some real innovation here!).

Watch this Screencast produced by Developer Division Community Program Manager Charlie Calvert to learn how Jeff's library enables the creation of scalable and responsive applications with minimal resources (threads/context switches). The library discussed in this Screencast can be downloaded from http://wintellect.com/PowerThreading.aspx.
Media Downloads:
Rating:
10
1
Hi Jeff

Nice to hear from you!  Regarding Outlook, I agree that spawning 50 threads is way over the top. There's a difference, though, between consuming 50 threads for the life of the application and starting two threads that will run for a second.

I wonder what Outlook is doing to consume that many threads. I never would have imagined that checking one's e-mail was that complicated!

Cheers

Joe

I find this quite useful and it probably does make developing code faster in some circumstances.
Thanks Jeff

Flatliner
Flatliner
With our thoughts we make the world.
Very clever idea Jeff. I got the feeling from the latest .NET framework that the APM model was being phased out by MS and replaced with the xxxAsync xxxCompleted event pattern. Just look at the code generated for WCF services for an example of this (even though I'm pretty sure it uses the APM pattern under the covers).  My only criticism of your AsyncEnumerator would be how large the iterator methods start to get when you have a fair bit of logic in each stage. As you said you can always switch back to separate event methods, but I'm wondering if there's not a happy medium somewhere in between, perhaps with sub-iterators, or some kind of iterator stack? Just thinking out loud...
Just to say that I am a big fan of Jeff's work, and have been using his AsyncResult and AsyncEnumerator for some time, on a number of different projects.  I use the AE when loading WPF controls to make multiple asycn calls to a DB when fetching various bits of data that the control needs.  Subsequently the control loads up much more quickly, and when all of the data returns, I can update the control, all without having to use the Dispatcher.

I do have one question though Jeff, you used to make the source code for your async library available on Wintellect, but now you only release a compiled library.  Why is this?  I have found that the latest release has caused a breaking change to my code, and so I am still using the version from May.  Can you at least outline what has changed between that version and Octobers release?

Steve
Have you guys looked at my lirary, which I created in Mid 2006

www.codeproject.com/KB/cs/AsynchronousCodeBlocks.aspx

This library with my accompanying Managed IOCP library were very similar to Microsoft's Parallel FX and Task Library. I wrote these libraries in Mid 2005 through 2006.

Regards,
Aditya.P
(Be Original)
CCR has been using almost idenctical syntax to do what Jeff is showing here for about 4 years (publicly). Jeff was even in some of our videos 3 years ago.

Various channel9 videos and PDC talk have examples... 
http://channel9.msdn.com/pdc2008/TL55/

http://channel9.msdn.com/tags/CCR/

CCR example for file read (from PDC session):

IEnumerator<ITask> CcrReadFileAsync(string file)
{
    var result = new Port<IAsyncResult>(); 
        using (var fs = new FileStream(file,…,FileOptions.Asynchronous))
        {

            var buf = new byte[fs.Length];
            fs.BeginRead(buf, 0, buf.Length, result.Post, null); 
            yield return result.Receive();
            var ar = (IAsyncResult)resultPort.Test(); 
            try  { 
                fs.EndRead(ar); 
                ProcessData(buf); 
            } catch { // handle exception }
      }
}

AQin
AQin
Hi

Thank you my dear friend. I like you and your books.............

With the CCR going commercial, how does this fit. Seems like dirct competition.
When would you use the CCR versus this?
Microsoft Communities