title: Designing an Interface for BackgroundWorker
body: <p>In my windows forms applications I have a class that extends a backgroundworker, let's call it ExtendedBGW1.cs in my form class I declare it like a member variable so I have scope for the entire class like so:</p>
  
  <pre><code>public partial class Main : Form
  {
      ExtendedBGW1 ebgw1;
  }
  </code></pre>
  
  <p>Later on in the forms constructor I do this</p>
  
  <pre><code>public Main()
  {
      InitializeComponent();
  
      ebgw1 = new ExtendedBGW1();
  
      InitializeBackgoundWorker();
  }
  </code></pre>
  
  <p>My InitializeBackgroundWoker() method looks like this</p>
  
  <pre><code>private void InitializeBackgoundWorker()
  {
      ebgw1.DoWork += new DoWorkEventHandler(ebgw1.worker_DoWork);
      ebgw1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(processWorkerCompleted);
      ebgw1.ProgressChanged += new ProgressChangedEventHandler(processProgressChanged);
      ebgw1.WorkerReportsProgress = true;
      ebgw1.WorkerSupportsCancellation = true;
  }
  </code></pre>
  
  <p>Now comes my design problem.  I know now that I am going to have different more classes like my extenededBGW1.cs that will extend BackGroundWorker so I was thinking that if I create a IExtenedBackGroundWorker I could do something like this.</p>
  
  <pre><code>public partial class Main : Form
  {
      IExtenedBackGroundWorker ebgw1;
  }
  </code></pre>
  
  <p>And still have the proper scope for the Main class.  Then I could just create whichever implementation of IExtendedBackGroundWorker I need later on.  </p>
  
  <p>I can make the interface for the methods and properties without much issue but am really running into a problem when I try to wire up the events correctly between the interface the base class and the Main class.</p>
  
  <p>Does anyone have any ideas?  </p>
  
  <p>Here are the errors I get in the Main</p>
  
  <pre><code>Error   1   Cannot assign to 'DoWork' because it is a 'method group'
  </code></pre>
  
  <p>and here is the error I get in my implemetation of the interface</p>
  
  <pre><code>Error   5   The event 'System.ComponentModel.BackgroundWorker.DoWork' can only appear on the left hand side of += or -= 
  </code></pre>
  
  <p>here is what my interface looks like right now:</p>
  
  <pre><code>interface IExtendedBackGroundWorker 
  {
      bool IsBusy { get; }
  
      bool WorkerReportsProgress { get; set; }
  
      bool WorkerSupportsCancellation { get; set; }
  
      List&lt;CompareObject&gt; ObjList { get; set; }
  
      string FilePath { get; set; }
  
      void RunWorkerAsync();
  
      void CancelAsync();
  
      void DoWork();
  
      void worker_DoWork(object sender, DoWorkEventArgs e);
  
      void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e);
  
      void ProgressChanged(object sender, ProgressChangedEventArgs e);
  }
  </code></pre>