Proper way to Dispose of a BackGroundWorker

后端 未结 5 1749
既然无缘
既然无缘 2020-11-28 11:44

Would this be a proper way to dispose of a BackGroundWorker? I\'m not sure if it is necesary to remove the events before calling .Dispose(). Also is calling .Dispose() ins

5条回答
  •  青春惊慌失措
    2020-11-28 12:12

    worker.Dispose() is not required, because Dispose() is automatically called. But before disposing the object you need to remove all events handlers.

    This article informs us about this.

    worker.RunWorkerCompleted -= new RunWorkerCompletedEventHandle(worker_RunWorkerCompleted);
    worker.DoWork -= new DoWorkEventHandler(worker_DoWork);
    

提交回复
热议问题