Reputation: 2831
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).
Upvotes: 2
Views: 2690
Reputation: 1227
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?
Upvotes: 1