2

I have been trying to understand when it would be best to use an Asynchronous Controller vs handling the task in a separate thread.

From research I believe Asynchronous is best used when there are multiple tasks to complete that at some point involve a single point entry on a resource. So the benefit in asp.net MVC would be to give back pooled thread so the UI can handle other UI events while some other thread continuous its processing before cloning its information back to the pooled thread.

Now lets say this task is to download a file off the server.. Will creating my own thread to spawn off and handle this operation be any less efficient?

With multi-threading I can handle data concurrency, how is this done using the asynchronous controller?

What are some examples in ASP.NET MVC that I should be using Asynchronous Controller vs my own thread?

I am new to ASP.NET MVC and trying to understand the concept better as I have exhaustively searched the internet and can not get a clear distinction between the two (for ASP.NET MVC).

1
  • Async IO on the server is mostly there to reduce the number of threads because each thread consumes 1MB of memory and some OS resources. This is really 99% of the story (on the server!). Commented Jun 9, 2015 at 17:47

1 Answer 1

1

Creating a thread is only useful if the result that you send back to the View does not depend on the action of the thread. Or put another way threads are useful for when time consuming processing is involved that the view doesn't need to have knowledge off.

One potential trap that I have come accross is if your controller is using session data IIS will block subsequent AJAX calls until it has been processed. Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

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

2 Comments

Actually isn't that an incorrect statement? The controller will by default wait for the returned view whether it be synchronous or not.
Thanks user3660362... Can you provide an example or scenario for asp.net mvc when you would use each case?

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.