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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:21:44+00:00 2026-05-27T02:21:44+00:00

I have a winform app, which shows some information in time, every time it

  • 0

I have a winform app, which shows some information in time, every time it loads the data, I set a delay time of 7 sec like this: System.Threading.Thread.Sleep(7000) so the info can be viewed. I want to have a buttom that allows me to jump to the next information without waiting.

The logic I use is as follows: get Information, if any, wait 7 sec, next data, and so on. So if I press the button I’d like to set that time to 0.

Is there any way to cancel the waiting period?

here is the code:

ManualResetEvent wait_handle = new ManualResetEvent(true);

{…}

private void TheLoop(object stateinfo)
    {
        bool hasInfo = true;            
        bool hasLines = GetLinesOnProduction();
        while (doLoop)
        {
            wait_handle.WaitOne();

            if (hasLines)
            {
                param1 = Lines[CurrentLine].line;
                param2 = Lines[CurrentLine].WO;

                //Here I query the DB for the CurrentLine Data                    
                ShowLineInformation(CurrentLine);
                ShowChartByHour(param1, param2, out hasInfo);
                if (hasInfo)
                    System.Threading.Thread.Sleep(7000);                                        
                //Here I move to the next line
                if (CurrentLine < Lines.Count - 1)
                    CurrentLine++;
                else
                {

                    CurrentLine = 0;  //Start all over again
                    hasLines = GetLinesOnProduction();
                }
            }
            else
            {
                System.Threading.Thread.Sleep(40000);  //(No Lines)Wait to query for lines again
                hasLines = GetLinesOnProduction();
            }
        }
    }

private void btnPauseResume_Click(object sender, EventArgs e)
    {
        if (btnPauseResume.Text == "Pause")
        {
            btnPauseResume.Text = "Resume";
            wait_handle.Reset();
        }
        else
        {
            btnPauseResume.Text = "Pause";
            wait_handle.Set();
        }
    }
  • 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-05-27T02:21:45+00:00Added an answer on May 27, 2026 at 2:21 am

    Instead of doing Thread.Sleep, you can use a wait event, and simply set it to cancel the wait. Something like this:

    var waiter = new AutoResetEvent(false);
    bool wasCanceled = waiter.WaitOne(7000);
    if(wasCanceled)
        // Jump to next...
    
    
    // Cancel the wait from another thread
    waiter.Set()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winform app which lists a batch of invoices in a gridview.
I have an .NET 4 .exe (Winform Desktop app) to which I have added
I have an application, which performs some custom data gathering, transformation and reporting. Currently,
I have a C# winform app which is doing a lot of calculation. there
I have this app written in VB.Net with winforms that shows some stats and
I have a WinForms app which I have compiled to DLL. I would like
I have an existing winform app which didn't use Program.cs. I wanted to add
I have a .net winforms app which has a few animation effects, fade ins
I have an MDI WinForms app in which the MDI parent form has a
I have a combo box on a WinForms app in which an item may

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.