Passage d'une méthode à un backgroundworker dowork

Dans le code ci-dessous, il est un moyen pour, au lieu de toujours s'abonner à la updateWorker_DoWork méthode, passer d'une méthode comme ceci

public void GetUpdates(SomeObject blah)
{
    //...
    updateWorker.DoWork += new DoWorkEventHandler(blah);
    //...
}


public void GetUpdates()
{
    //Set up worker
    updateWorker.WorkerReportsProgress = true;
    updateWorker.WorkerSupportsCancellation = true;
    updateWorker.DoWork += new DoWorkEventHandler(updateWorker_DoWork);
    updateWorker.RunWorkerCompleted +=
        new RunWorkerCompletedEventHandler(updateWorker_RunWorkerCompleted);
    updateWorker.ProgressChanged +=
        new ProgressChangedEventHandler(updateWorker_ProgressChanged);

    //Run worker
    _canCancelWorker = true;
    updateWorker.RunWorkerAsync();
    //Initial Progress zero percent event
    _thes.UpdateProgress(0);
}
InformationsquelleAutor James | 2010-08-13