title: How to wrap code in a lambda expression using a BackgroundWorker in vb.net?
body: <p>Consider the following C# code:</p>
  
  <pre><code>private void SomeMethod()
  {
      IsBusy = true;
      var bg = new BackgroundWorker();
      bg.DoWork += (sender, e) =&gt;
      {
        //do some work
      };
      bg.RunWorkerCompleted += (sender, e) =&gt;
      {
        IsBusy = false;
      };
      bg.RunWorkerAsync();
  }
  </code></pre>
  
  <p>I know VB.NET won't allow directly referencing <code>DoWork</code> like that and you have to setup the worker by saying <code>Private WithEvents Worker As BackgroundWorker</code> and explicitly handling the <code>DoWork</code> event as follows:</p>
  
  <pre><code>Private Sub Worker_DoWork( 
              ByVal sender As Object,
              ByVal e As DoWorkEventArgs) _
              Handles Worker.DoWork
  
      ...
  
  End Sub
  </code></pre>
  
  <p>However, I'd like to be able to implement a method like <code>SomeMethod</code> from the C# example in VB.net. Likely this means wrapping the Backgroundworker in another class (which is something I want to do for dependency injection and unit testing anyway). I'm just not sure how to go about it in a simple, elegant way.</p>