ASP.NET MVC 2 asynchronous action with timeout

2.9k Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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.

1
On

You may take a look at asynchronous controllers.