title: Creating BackgroundWorker with Queue
body: <p>I need to create queue and use it with BackgroundWorker. So I can add operations and when one is done next is starting in background. I found this code by google:</p>
  
  <pre><code>public class QueuedBackgroundWorker&lt;T&gt;
  {
      public void QueueWorkItem(
          Queue queue,
          T inputArgument,
          Func&lt;T&gt; doWork,
          Action workerCompleted)
      {
          if (queue == null) throw new ArgumentNullException("queue");
  
          BackgroundWorker bw = new BackgroundWorker();
          bw.WorkerReportsProgress = false;
          bw.WorkerSupportsCancellation = false;
          bw.DoWork += (sender, args) =&gt;
          {
              if (doWork != null)
              {
                  args.Result = doWork(new DoWorkArgument&lt;T&gt;((T)args.Argument));
              }
          };
          bw.RunWorkerCompleted += (sender, args) =&gt;
          {
              if (workerCompleted != null)
              {
                  workerCompleted(new WorkerResult&lt;T&gt;((T)args.Result, args.Error));
              }
              queue.Dequeue();
              if (queue.Count &gt; 0)
              {
                  QueueItem&lt;T&gt; nextItem = queue.Peek() as QueueItem&lt;T&gt;;
                  nextItem.BackgroundWorker.RunWorkerAsync(nextItem.Argument);
              }
          };
  
          queue.Enqueue(new QueueItem&lt;T&gt;(bw, inputArgument));
          if (queue.Count == 1)
          {
              QueueItem&lt;T&gt; nextItem = queue.Peek() as QueueItem&lt;T&gt;;
              nextItem.BackgroundWorker.RunWorkerAsync(nextItem.Argument);
          }
      }
  }
  
  public class DoWorkArgument&lt;T&gt;
  {
      public DoWorkArgument(T argument)
      {
          this.Argument = argument;
      }
      public T Argument { get; private set; }
  }
  
  public class WorkerResult&lt;T&gt;
  {
      public WorkerResult(T result, Exception error)
      {
          this.Result = result;
          this.Error = error;
      }
  
      public T Result { get; private set; }
      public Exception Error { get; private set; }
  }
  
  public class QueueItem&lt;T&gt;
  {
      public QueueItem(BackgroundWorker backgroundWorker, T argument)
      {
          this.BackgroundWorker = backgroundWorker;
          this.Argument = argument;
      }
  
      public T Argument { get; private set; }
      public BackgroundWorker BackgroundWorker { get; private set; }
  }
  </code></pre>
  
  <p>But I have problem with doWork and workerCompleted. I get error: </p>
  
  <blockquote>
    <p>Delegate 'Func' does not take 1 arguments</p>
  </blockquote>
  
  <p>How can I fix this? How should I change parameters? Thanks</p>