Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Climbing the cliffs of C#
Browse by Tags · View All
Community Life 19
ASP.NET MVC 9
.NET 3
Software Development 3
CI 3
Source Control 3
C# 2
Myself & I 2
Me 2
ASP.NET 2

Archive · View All
January 2012 12
November 2012 3
June 2012 3
April 2012 3
August 2012 2
July 2012 2
February 2012 2
January 2013 1
December 2012 1
October 2012 1

Set the AsyncTimeout attribute for your async controllers

Dec 7 2011 12:00AM by simone   

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.
  • NoAsyncTimeoutAttribute – if you want to set the timeout to indefinte (ie the action will run forever)

Here following a very simple example of an Async controller with the AsyncTimeout attribute set to 10 minutes.

public class SyncController : AsyncController
{
    [AsyncTimeout(600000)]
    public void SyncAllAsync()
    {
        syncManager.OutstandingOperations.Increment();
        var bg = new BackgroundWorker();
        bg.DoWork += (o, e) => DoStuff("Some other stuff", e);
        bg.RunWorkerCompleted += (o, e) =>
                 {
                     AsyncManager.Parameters["model"] = e.Result;
                     AsyncManager.OutstandingOperations.Decrement();
                 };
        bg.RunWorkerAsync();
    }
    
    public ActionResult SyncAllCompleted(SyncViewModel model)
    {
        return View(model);
    }
    
    private void DoStuff(string input, DoWorkEventArgs e)
    {
        SyncViewModel model = new SyncViewModel();
        Thread.Sleep(60000);
        model.Text=input;
        e.Result = model;
    }
}

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.


Republished from CodeClimber [4 clicks].  Read the original version here [4 clicks].

simone
850 · 0% · 34
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]