views:

351

answers:

2

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?

A: 

You may take a look at asynchronous controllers.

Darin Dimitrov
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
A: 

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