BackgroundWorker: is it dead after executing the DoWork () handler?

What I get is when you finish working with the DoWork () handler, and then maybe run RunWorkerCompleted (), can you call RunWorkerAsync () again and re-enable the DoWork () handler, or you need to do another one "new" operation and create a new BackgroundWorker? It’s just interesting if any disposal or other cleaning will be done after this happens, and now you no longer have a viable bg worker.

+3
source share
1 answer

You can call RunWorkerAsyncwhatever you like. You do not need to create a new object BackgroundWorker.


, , BackgroundWorker . , : , RunWorkerAsync, . RunWorkerCompleted:

void DoWorkButton_Click(object sender, EventArgs e)
{
    DoWorkButton.Enabled = false;
    Worker.RunWorkerAsync();
}

void Worker_DoWork(object sender, DoWorkEventArgs e)
{
    // Do some async operation.
}

void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    try
    {
        // Do some updates.
    }
    finally
    {
        DoWorkButton.Enabled = true;
    }
}
+2

All Articles