Say you want to copy from one stream to another, using only the asynchronous methods on Stream. How can you loop such requests continually in order to process the whole stream? Is that even possible?

In the March 2008 issue of MSDN Magazine, Stephen Toub demonstrates, in C# and Visual Basic, a truly asynchronous implementation that copies all of the data from one stream to another. Stephen uses a continuation-passing design to package everything that comes after the asynchronous request and pass that as a closure to be executed when the asynchronous request completes.

For more .NET programming guidance from Steve, check out previous .NET Matters installments in our MSDN Magazine archives.