You will be able to accomplish your task using BackgroundWorker
. It is a well known class, and many people have used it.
The new C# 5 async
and await
keywords basically just make it easier to write readable asynchronous code. There may be fewer tutorials and examples of how to accomplish various tasks with these keywords rather than BackgroundWorker
.
Unless you need to use an older version of C#, I suggest learning how to use async
and await
.
What you are asking is not about how to code in MVC or in ASP.NET, I think it's about using a different approach.
The architecture that you kind of describe is very similar to a Single Page Application (SPA) where the server-side turns into a thin API and all the logic of the application is moved to client-side code written in JavaScript (logic, navigation, routing, rendering, etc..).
Of course you could have a "hybrid" solution using MVC to deal with logic, navigation, routing, etc.. and have some API's to serve some data to some pages that use some client-side code.
However, I think this would add complexity to the application because there would be a thick-server (MVC) and in some parts a semi-thick-client plus the fact that there would be an API.
So it would end up with MVC + API + Client-Side code.
The SPA approach follows the thin-server / thick-client. The server only acts as a repository of Data + some authentication logic (if needed) and the client has all the logic to run the application in the browser. All the communications between the browser and server use AJAX. This way we reduce the complexity by only using an API + JavaScript.
I don't know if this answer would help you, but I think that if you start to think about using AJAX more and more in MVC, you will end up with a SPA.
Best Answer
It's never absolutely necessary for a controller to be async. Calls to controller methods will eventually return. However, it might be desirable to hand off a long-running task to a thread, so that the web server is not blocked for a long period of time.
I wouldn't bother making every controller asynchronous. There is some overhead involved in creating new threads; making every controller asynchronous might actually slow things down.
http://msdn.microsoft.com/en-us/library/ee728598(v=vs.100).aspx