Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Asynchronous Patterns in ASP.NET Web Forms vNext

Asynchronous Patterns in ASP.NET Web Forms vNext

Asynchronous programming is all the range these days and for good reason, when properly used it can significantly improve the throughput of I/O bound applications. And while some may think this of the realm of new and esoteric languages, even Web Forms is getting in on the game.

ASP.NET Web Forms already has some asynchronous support in the form of

These can greatly improve the throughout on websites, but neither option is widely used. The primary reason people don’t bother is that the APIs are complex and they don’t really support multiple async operations during a single page request. While it can be done, but it requires writing a custom IAsyncResult to daisy chain the calls together.

With Web Forms vNext and the new “await” keyword the use of asynchronous code becomes easy. This can be used in conjunction with PageAsyncTask to greatly reduce the amount of code. Alternately you can replace the normal page events with methods that return “async Task” and write your code as if it were synchronous.

We talked with Damian Edwards of Microsoft about this new capability.

InfoQ: What was the main reason Microsoft decided to add the new async support to Web Forms?

Since part of vNext is about simplifying async programming across the .NET Framework, we wanted to ensure that various parts of ASP.NET, including web-forms could support the new Task-centric await programming model. The beginning of this work can be seen in the Async CTPs to date.

InfoQ: In the future should developers default to writing in the async style or should this be something they switch to only when performance becomes a concern?

The answer to this can probably be as much philosophical as technical. I would recommend using asynchronous programming constructs (async pages in the case of web-forms) for cases where you either already know your will be performing long-running/high-latency work, or where you reasonably suspect that in the future you may very well need to add long-running/high-latency work. In more concrete terms if you have work that you know will take 250ms. or more of latency before returning results then there is a good chance you will likely benefit from switching over to async pages. If you have work where the latency is "spiky" (i.e. latency can randomly jump up by a few hundred ms. or even a few seconds), then async pages will also be of benefit.

InfoQ: Do you have any guidelines or recommended tutorials for using the currently available async features in Web Forms 4.0?

Beyond what's available on the web today there isn't anything new that we have. For vNext we will have updated samples, docs, blog posts, etc...

InfoQ: Is there anything people should be doing to prepare for moving from the current async features to the new ones?

Not really. If developers are using the existing async entry points in ASP.NET today, they will all continue to work in vNext. From an ASP.NET internals perspective there isn't really any fundamental change. Internally ASP.NET vNext for the most part continues to perform much of its work asynchronously (caveat the usual bug fixes and minor tweaks that happen from release to release). The main change in vNext is that the public APIs exposed to developers are being updated to support the Task based await programming pattern.

InfoQ: Will you be releasing a stand-alone CTP of Web Forms vNext or do we need to wait until the general beta of the next version .NET framework?

The usual answer - we can't comment on release timelines right now. However since web-forms is an intrinsic part of ASP.NET and the .NET Framework, the new await support will be available when vNext versions of the overall .NET Framework are available.

InfoQ: Are there any async features you would like to see down the road? By that I mean things that you know won't be in vNext but may consider in the future.

Since we're still working on vNext its way too early to know what new async scenarios we would want to build in "vNext++" -).

You can learn more about the features in Web Forms vNext in Damian’s TechEd Presentation: Web Forms: Reports of My Death Are Greatly Exaggerated.

Rate this Article