5

I want to write an asynchronous action in ASP.NET MVC 2 that waits up to 5 seconds for an event to occur. If the event occurs then the server responds with a result, otherwise the request times out.

What is the best way to achieve this?

thatismatt
  • 9,832
  • 10
  • 42
  • 54

2 Answers2

3

Use the [AsyncTimeout] attribute. If the asynchronous action hasn't completed within the specified time, a TimeoutException will be thrown. You can use an exception filter (like [HandleError]) to watch for these exceptions and handle them appropriately.

Levi
  • 32,628
  • 3
  • 87
  • 88
  • Or alternatively use the AsyncManager.Timeout property within the action method. It's the same effect as the AsyncTimeout attribute but is useful when you want more control, e.g. reading the timeout from config. – Stuart Hallows Apr 03 '13 at 05:21
1

You may take a look at asynchronous controllers.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Sorry, my question obviously wasn't very precise. I am using the AsyncController already. But I want to know what I write within my action method to achieve this. The waiting on an event with a timeout is the cruscial aspect. – thatismatt Mar 29 '10 at 08:44