Tag Archives: async

Asynchronous ASP.NET pages

I ran into a blatant bug where someone had created a worker thread from the page codebehind to allow a page to launch a long-running process. Needless to say, it did not work. In this case, the code being called eventually tried HttpContext.Current, because the Request object was out of scope, but in addition it was gone by now, too. They did this (I guess) to avoid page timeouts, but the errors occurring on the worker thread were not being reported to the user (or even logged), so it was a Bad Thing to do.

The funny thing was that I was able to get it working simply by adding Async=”true” to the page tag, and directly calling the method that had been passed to the worker thread. I did not have to do declare an IAsyncResult-returning method or anything. I know that async pages are helpful in keeping ASP.NET thread pool threads available, but had never heard of using them to extend the Request scope like this. It seems like, in addition to the overhead of setting up the async handler, there could be is some danger in keeping a Request around like that…will see.