I have noticed a few places on my website where I talk to third-party resources. I have seen several recommendations (e.g., MSDN Magazine: Asynchronous Pages in ASP.NET 2.0) that such code should run asynchronously, if only to avoid saturating the thread pool. Suppose I introduce several functions like this:

public static void LoadThirdPartyInfo(/*Arguments*/)
{
    Page page = (Page) HttpContext.Current.CurrentHandler;
    if(page.IsAsync)
    {
        page.AddOnPreRenderCompleteAsync( //...
    }
    else
    {
        //Oops...
    }
}

At this point, I could:
1. Remove (or keep) the else clause and try to be careful to only call it on Async pages, possibly adding some logging to detect when this is done incorrectly.
2. Same as #1, but use Async="True" on new pages.
3. Same as #1, but use Async="True" on all pages.

I am unsure if there are risks to introducing unnecessary Page Async directives. They don't seem to break anything.

Question: Is it OK to introduce spurious Async directives?

Note: I am using .Net 4.0, but am open to responses targeting .Net 4.5 .

Related posts

Recent Viewed