Code Climber

Set the AsyncTimeout attribute for your async controllers

Today I decided to convert an action that was making various long calls to external webservices to be asynchronous. With the synchronous version it was long but still under the default script timeout of ASP.NET, so I was very surprised when the async version was returning a System.TimeoutException, even if it was still taking the same amount of time. I tried increasing the ScriptTimeout, but still no luck: the page was timing out.

After a bit of searching online I found out that for some strange reason, async controllers have a different timeout, specified by the Timeout property of the AsyncManager; and by default this value is 45 seconds.

Instead of manually setting this value in your action, you can use two action attributes so that infrastructural code doesn’t interfere with your actions’ code:

AsyncTimeoutAttribute – you can set the timeout of the async action. It is specified in milliseconds: 10 minutes is 600000.

The code doesn’t do a lot, just fires up the background worker and calls the DoStuff method asynchronously. I just realize I could have also probably used the TPL and the Task with continuation… maybe I’ll write an update to this blog in the next days while I work on my project and need to process more “stuff” in parallel.