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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:30:41+00:00 2026-06-16T19:30:41+00:00

I like to use the Sleep() function in a Windows Forms project, but the

  • 0

I like to use the Sleep() function in a Windows Forms project, but the Sleep() is executed before anything else. I read that i should flush using fflush(), but i don’t know what to flush. Can someone help me?

The code:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {                    

             this->label1->Visible= false;
             this->button1->Visible= false;


             r = (float)rand()/(float)RAND_MAX;                              
             r = r*100000;
             i = r;
             r = r - i;              

             String^ strR = "" + r;
             this->label2->Text = strR;


             if(r >= 0.5)
             {
                 this->pictureBox1->Visible= true;
                 this->pictureBox1->BackColor = System::Drawing::Color::Blue;                    
             }
             else
             {
                 this->pictureBox1->Visible= true;
                 this->pictureBox1->BackColor = System::Drawing::Color::Red;                                         
             }   

             Sleep(500);

         }
  • 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-16T19:30:42+00:00Added an answer on June 16, 2026 at 7:30 pm

    The call to Sleep() is blocking your main (UI) thread, which prevents the message pump from updating your controls.

    In this case, it doesn’t appear that the call to Sleep really serves a purpose, other than blocking your UI – if you want to prevent the button from being pressed again, a better option would be to disable it, then use a timer (System::Windows::Forms::Timer) with a 500 ms interval to re-enable the button.

    By using a timer, you won’t block the UI thread, which allows your controls to stay active, but you still prevent the user from pressing the button.

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

Sidebar

Related Questions

Knowing that while Node.js is working asynchronously, writing something like this: function sleep() {
I like to use a simple Git workflow for static web sites but I
I use a pipe to read the output of a function by passing it
My C#-program should be by opening perform a powershellfunction, looks like this: function RunIE
I would like to use the timeout command with an own function, e.g.: #!/bin/bash
I have some synchronous code that looks like this: function bulk_upload(files, callback) { for
I'm using jquerys slideToggle method and would like to add a callback function that
I'm trying to get use of setConnectTimeout function like this: protected HttpURLConnection getConnection() throws
I have an array of Integers in Java, I would like use only a
I use RingtonePreference and would like to use default notification sound as the default

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.