BackgroundWorker for Multiple Operations
<p>I'm trying to get get my BackgroundWorker to execute methods sequentially, one after the other, but I'm having no luck.</p>

<p>I feel it may be worthwhile to mention that I'm a SQL Developer by profession and I'm expanding my development scope.  I see no harm in that :)</p>

<p>I realize I can spawn new threads for the number of operations I have going but the operations I want to execute on the BackgroundWorker executes stored procedures in SQL Server, so running multiple queries on multiple threads all at once while hundreds of people are working on the server isn't ideal, since I store large volumes of data in my ETL tables.</p>

<p>So essentially what I have now is the following:</p>

<pre><code>internal async void MethodA(DateTime startDate, DateTime endDate)
    {
        // Execute Stored Procedure which populates an ETL Table
        // I use a SQLCommand object and call it using
        // await sqlCommand.ExecuteNonQueryAsync();
    }

internal async void MethodB(DateTime startDate, DateTime endDate)
    {
        // Execute Stored Procedure which populates another ETL Table
        // I use a SQLCommand object and call it using
        // await sqlCommand.ExecuteNonQueryAsync();
    }
</code></pre>

<p>I want to call these methods one after the other like this:</p>

<pre><code>private void btnCreateFile_Click(object sender, EventArgs e)
    {
        ProcessMethodA();
        ProcessMethodB();
    }


void ProcessMethodA()
    {
        if (!backgroundWorker1.IsBusy)
        {
            Cursor = Cursors.WaitCursor;
            dtLossRatio.Clear();
            lblProgress.Visible = true;
            lblProgress.Text = "Building ETL A...";
            pbProcessWait.Visible = true;
            pbProcessWait.Location = new Point(420, 413);
            process = "ProcessA";
            backgroundWorker1.RunWorkerAsync();
        }
    }


void ProcessMethodB()
    {
        if (!backgroundWorker1.IsBusy)
        {
            Cursor = Cursors.WaitCursor;
            dtLossRatio.Clear();
            lblProgress.Visible = true;
            lblProgress.Text = "Building ETL B...";
            pbProcessWait.Visible = true;
            pbProcessWait.Location = new Point(456, 413);
            process = "ProcessB";
            backgroundWorker1.RunWorkerAsync();
        }
    }
</code></pre>

<p>For my BackgroundWorker I have this:</p>

<pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        switch (process)
        {
            case "ProcessA":
                logic.MethodA(DateTimePicker1.Value, DateTimePicker2.Value);
                break;
            case "ProcessB":
                logic.MethodB(DateTimePicker3.Value, DateTimePicker4.Value);
                break;
        }
    }
</code></pre>

<p>I have a feeling these process changes should perhaps be altered in</p>

<pre><code>private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
    }
</code></pre>

<p>I'm just not sure how to do this.</p>

<p>I've tried using a Task but I have no idea how to report the completion of one task for the code to start executing a new operation:</p>

<pre><code>Task ExecuteProcessA()
    {
        Action invoker = new Action(ProcessA);
        return Task.Run(invoker);
    }
</code></pre>

<p>Any assistance would be great!</p>