Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using statement for background worker

I have been looking over several examples of backgroundworkers and I ran across code that looks similar to this

public class MyClass
{
  public MyClass()
  {
    using(BackgroundWorker _Worker = new BackgroundWorker { WorkerReportsProgress = true})
    {
      _Worker.DoWork += (s, args) =>
      {
        ...
      };
    }
    _Worker.RunWorkerAsync();
  }
}

I have not been using the "using" statment in my code like this. I ran across something similar while using the Code Rush trial, which made me come back to this code and question if i should be doing this or not. Please help me understand if/why this would be best practice. Thanks.

like image 976
poco Avatar asked Oct 11 '22 07:10

poco


1 Answers

Actually BackgroundWorker does not need to be disposed, see here. So there is no need to have the using clause

like image 182
thumbmunkeys Avatar answered Oct 12 '22 22:10

thumbmunkeys