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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

You may take a look at asynchronous controllers.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.