Is a background worker in an async controller?

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?

+5
source share
4 answers

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

+7

BackgroundWorker , : . .

ThreadPool.QueueUserWorkItem, , : Task.Factory.StartNew(...).

+1

, ( , , ).

, . - BackgroundWorker, RunWorkerCompleted.

, e.Result DoWork, e.Result RunWorkerCompleted (, e.Error , DoWork).

, , , , using, , BackgroundWorker . , - RunWorkerCompleted. - , - ?

0

, , , , , . , .

0

All Articles