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

  • Home
  • SEARCH
  • 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 260277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:20:04+00:00 2026-05-11T22:20:04+00:00

Did some searches here & on the ‘net and haven’t found a good answer

  • 0

Did some searches here & on the ‘net and haven’t found a good answer yet. What I’m trying to do is call a button twice within the same class in C#.

Here’s my scenario –

I have a form with a button that says “Go”. When I click it the 1st time, it runs through some ‘for’ loops (non-stop) to display a color range. At the same time I set the button1.Text properties to “Stop”. I would like to be able to click the button a 2nd time and when that happens I would like the program to stop. Basically a stop-and-go button. I know how to do it with 2 button events, but would like to utilize 1 button.

Right now the only way to end the program is the X button on the form.

I’ve tried different things and haven’t had much luck so far so wanted to ask the gurus here how to do it.

BTW, this is a modification of a Head First Labs C# book exercise.

Thanks!

~Allen

  • 1 1 Answer
  • 2 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-05-11T22:20:05+00:00Added an answer on May 11, 2026 at 10:20 pm

    You would need to use Multithreading (launch the process intensive code asynchronously in a separate thread), for instance, using the BackgroundWorker object in .NET 2+. This would be necessary because your UI will not respond to the user’s click until the loop running in the Start method is completed. It is quite irrelevant if you use the same button or another one to toggle the process, because the processor is busy processing the loop.

    The BackgroundWorker has a property called WorkerSupportsCancellation which needs to be true in this scenario. When the user clicks Stop you would invoke the CancelAsync method of the BackgroundWorker.

    See MSDN for a good example. Also DreamInCode has a good tutorial which seems quite similar to your requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know of any good libraries for this? I did some searches and didn't come
I did some googling to try to answer this question but even after that
I always believe they did, but seeing some answers here make me doubt... Can
I did some tests a while ago and never figured out how to make
I did some HTTP monitoring with WireShark. Are there more tools like this that
I did some timing tests and also read some articles like this one (last
To analyze lots of text logs I did some hackery that looks like this:
Does anyone have any thoughts on this method? I have did some performance testing
Did anyone try that feature and has some feedback? Or Does anyone know some
I have some code which I did not originally create that uses _beginthreadex 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.