how can I use BackGroundWorker to make continuous execution for a method which is depends on user input to stop?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3065700/how-to-start-and-stop-a-continuously-running-background-worker-using-a-button">How To Start And Stop A Continuously Running Background Worker Using A Button</a>  </p>
</blockquote>



<p>I have 2 buttons the first one it's name "Continuous" .. the second one "Stop"</p>

<p>I want to call a method when press the continuous button :</p>

<pre><code>private void continuous_Click(object sender ,EvantArgs e) 

      {   

     // continuous taking pictures ...

      }
</code></pre>

<p>my question is : how can I stop the execution by pressing the stop button ??</p>

<p>I've written a code to take a picture and I've succeeded to take pictures ...
now I want the camera to take continuous snapshots ... but if I press stop button the camera should stop taking pictures ... </p>

<p>I've used BackGroundWorker but the code does not work !!!</p>

<p>this is the code :</p>

<pre><code>private void ContinousSnaps_Click(object sender, EventArgs e)
    {

        Contiguous.DoWork += Contiguous_DoWork;
        Contiguous.RunWorkerCompleted += Contiguous_RunWorkerCompleted;
        Contiguous.RunWorkerAsync();
    }

    private void Contiguous_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 0; ; i++) TakeSnapShotCommand();
    }

    private void Contiguous_RunWorkerCompleted(object sender,
                                   RunWorkerCompletedEventArgs e)
    {
        MessageBox.Show("complete");
    }

    //------------------------------------------------------------------//

    private void Stop_Click(object sender, EventArgs e)
    {
        Contiguous.CancelAsync();


    }

  //--------------------------------------------------------------------//
</code></pre>

<p>how can I achieve the result that I want ?! </p>
