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 8340897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:18:32+00:00 2026-06-09T05:18:32+00:00

I have a button click event for continue: private void button3_Click(object sender, EventArgs e)

  • 0

I have a button click event for continue:

 private void button3_Click(object sender, EventArgs e)
        {
            if (backgroundWorker1.IsBusy)
            {
                button2.Enabled = true;
                button3.Enabled = false;
            }
            else
            {
                backgroundWorker1.RunWorkerAsync();
                button2.Enabled = true;
                button3.Enabled = false;
            }

        }

And a button click event for pausing:

private void button2_Click(object sender, EventArgs e)
        {
            if (backgroundWorker1.WorkerSupportsCancellation == true)
            {
                backgroundWorker1.CancelAsync();
                button3.Enabled = true;
                soundPlay = false;
                stop_alarm = true;
            }

        }

The problem is with the button3 click event the continue code sometimes the background is busy so i can enable false/true the buttons but the backgroundworker is keep working.
I want to pause the DoWork event and to continue.

This is my DoWork event:

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            while (true)
            {
                if ((worker.CancellationPending == true))
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    if (tempCpuValue >= (float?)numericUpDown1.Value || tempGpuValue >= (float?)numericUpDown1.Value)
                    {
                        soundPlay = true;
                        blinking_label();
                    }
                    else
                    {
                        soundPlay = false;
                    }
                    cpuView();
                    gpuView();
                    Thread.Sleep(1000);
                }
            }
        }
  • 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-09T05:18:33+00:00Added an answer on June 9, 2026 at 5:18 am

    You could do this with a Thread instead of a BackgroundWorker?

    With a Thread, in its working subroutine you could put the thread into an infinite sleep inside a try/catch block that catches ThreadInterruptedException. So, as it loops through whatever it’s working on, you could look at the value of a boolean flag to know whether or not to sleep, and then call Thread.Sleep(Timeout.Infinite). When you catch ThreadInterruptedException you set the flag to false and continue to execute.

    To make the thread resume from your UI, you would set the ‘pause’ flag to false and call workerThread.Interrupt() on your thread (assuming you called it workerThread, that is).

    Idea sourced from here

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

Sidebar

Related Questions

I have a GriView and implemented RowDataBound event like below protected void gvwSearchResult_RowDataBound(object sender,
I have a button click event handler with a switch case in it that
I have a button click event that takes information from controls and enters it
I have a local thread that is started on button-click event from the main
I have MainWindow with a button, under the button click event I want MainWindow
I have a fairly simple code, a button click event, with the first line
I have two event handlers wired up to a button click in a Windows
I have the following code bound to the click event of a button: function
I have event Button that creates text box in run time. Private Sub Button1_Click(ByVal
I have a button click on which i have to call a webmethod 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.