Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:57:19+00:00 2026-06-17T19:57:19+00:00

Possible Duplicate: How To Start And Stop A Continuously Running Background Worker Using A

  • 0

Possible Duplicate:
How To Start And Stop A Continuously Running Background Worker Using A Button

I have 2 buttons the first one it’s name “Continuous” .. the second one “Stop”

I want to call a method when press the continuous button :

private void continuous_Click(object sender ,EvantArgs e) 

      {   

     // continuous taking pictures ...

      }

my question is : how can I stop the execution by pressing the stop button ??

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 …

I’ve used BackGroundWorker but the code does not work !!!

this is the 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();


    }

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

how can I achieve the result that I want ?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:57:20+00:00Added an answer on June 17, 2026 at 7:57 pm

    Try and see if this is going to work:
    In your _DoWork event:

        private void Contiguous_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 0; ; i++)
            {
                if (Contiguous.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                TakeSnapShotCommand();
            }
        }
    

    And in the Stop_Click to the following:

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

    Also make sure you allow cancellation (and if you want to take my advice here – move these event registrations in a the form load, so they will be executed once, not every time the button is clicked – leave just the Continuous.RunWorkerAsync()):

        // your form load <---
        private void Form1_Load(object sender, EventArgs e)
        {
            Contiguous.DoWork += Contiguous_DoWork;
            Contiguous.RunWorkerCompleted += Contiguous_RunWorkerCompleted;
            Contiguous.WorkerSupportsCancellation = true; // allowing cancellation
        }
    
        private void ContinousSnaps_Click(object sender, EventArgs e)
        {
            // not a bad idea if you disable the button here at this point
            Contiguous.RunWorkerAsync();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: ASP.NET MVC quick start - a one-stop tutorial? I am starting a
Possible Duplicate: Start thread with member function I have recently been playing around with
Possible Duplicate: How to know if Process.Start() is successful? I have a process similar
Possible Duplicate: How to get notified of UITableViewCell move start and end I have
Possible Duplicate: Delay in Recording using avaudiorecorder I am running an app on Xcode4
Possible Duplicate: How to automatically start your service after install? I have a Visual
Possible Duplicate: start Activity from an other Activity with Tabs I have a TabHost
Possible Duplicate: Class names that start with C. I am a newbie using c++
Possible Duplicate: Start background process from .bashrc I'm executing a script in .bashrc and
Possible Duplicate: J2me detecting first start of application I'm developing a J2ME application and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.