Implementing the Asynchronous Programming Model

After the fun I had yesterday building my Yahoo Services Search Proxy (see my previous post) today I decided to see if I could extend my proxy to support the Asynchronous Programming Model.

And what is more, I wanted to use the TDD process to do it.  That meant that I would have to stub out implementations of things like HttpWebRequest/Response etc.  It took all afternoon and when I got done I had created my own implementation of the APM both as a provider and consumer (a really great learning experience) but in the end I must confess that I began to wonder if it makes sense to add this to the proxy class.

Monday and Tuesday I was in Jeff Richter's most excellent Advanced Threading class where we covered many of the reasons why the APM is a beautiful thing.  To be honest with you I only thought I understood threading before.  Now I know there is so much more that I don't truly understand about it.  However, one thing I know for sure.  If you want to build highly scalable and robust apps you should be asynchronous as much as possible.  There are two styles of async for .NET.  One is the APM which is interface and callback based and the other is the Event Based programming model (EPM) which is designed for client side developers.

Jeff told us that he is not a fan of EPM but to be honest with you I think that many developers will never do APM (even though it isn't that hard to do).  EPM is much easier but as Jeff points out probably not suitable outside of a client side project.

The more I think about it... WCF implements the APM in generated proxies (with the /async switch on SvcUtil).  If they can do it... I can do it.  I have the guts of it working...  Now I just need to think through the design a little more.  My class will then implement both APM and EPM so you can take your pick.

Fun to be coding again... so much to learn.