Inside the asp.net mvc 2 controller, I have the following code:
using (BackgroundWorker worker = new BackgroundWorker()) { worker.DoWork += new DoWorkEventHandler(blah); worker.RunWorkerAsync(var); }
My question is: is this async code meaning that it starts a new thread and the controller returns a view while blah is executed in parallel?
If not, how would you achieve these results?
MVC 2 , AsyncController, MVC. AsyncController, . , "Async" . , , Blah(), BlahAsync(), ( BlahCompleted()):
public virtual void BlahAsync() { AsyncManager.OutstandingOperations.Increment(); var service = new SomeWebService(); service.GetBlahCompleted += (sender, e) => { AsyncManager.Parameters["blahs"] = e.Result; AsyncManager.OutstandingOperations.Decrement(); }; service.GetBlahAsync(); } public virtual ActionResult BlahCompleted(Blah[] blahs) { this.ViewData.Model = blahs; return this.View(); }
AsyncController : MVC AsyncController
BackgroundWorker , : . .
BackgroundWorker
ThreadPool.QueueUserWorkItem, , : Task.Factory.StartNew(...).
ThreadPool.QueueUserWorkItem
Task.Factory.StartNew(...)
, ( , , ).
, . - BackgroundWorker, RunWorkerCompleted.
RunWorkerCompleted
, e.Result DoWork, e.Result RunWorkerCompleted (, e.Error , DoWork).
e.Result
DoWork
e.Error
, , , , using, , BackgroundWorker . , - RunWorkerCompleted. - , - ?
using
, , , , , . , .