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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:48:49+00:00 2026-06-08T08:48:49+00:00

Possible Duplicate: Why does Thread.sleep() behave in this way This is a simple code

  • 0

Possible Duplicate:
Why does Thread.sleep() behave in this way

This is a simple code that i have written:

    private void button1_Click(object sender, EventArgs e)
    {
        label1.Text = "first";
        Thread.Sleep(1000);
        label1.Text = "second";
    }

When this code is executed and button is clicked, label1 displays text as only ‘second’ but not ‘first’. I checked using break point, and statement label1.text=”first” is executed but label does not display ‘first’. Why is this so?

  • 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-08T08:48:50+00:00Added an answer on June 8, 2026 at 8:48 am

    Because your code is running on the UI thread.

    When your app is running and you’re not clicking on things, the application’s main thread is rushing around, waiting for events, processing Windows messages, and painting the screen. When you click your button, the app stops doing those things, and runs your function instead. While it’s running your method, it can’t paint the screen. Your function sets the label to “First”, blocks the thread for a second, then sets the label to “second”.

    When you return, control passes back to the application, which is then free to repaint the form. It repaints it using the “second” label. The message loop never had chance to paint it with the “first” label.

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

Sidebar

Related Questions

Possible Duplicate: When does Java's Thread.sleep throw InterruptedException? I saw we have to catch
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class
Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
Possible Duplicate: Why does this Random Number Generator not random? I have this test
Possible Duplicate: Why does simple C code receive segmentation fault? I am working in
Possible Duplicate: How does @synchronized lock/unlock in Objective-C? I have an application that creates
Possible Duplicate: Does PHP have threading? I found this: http://php.net/manual/en/function.pcntl-fork.php But I can't tell
Possible Duplicate: Does JavaScript have a range() equivalent? Is there a way to declare
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: What does “(void) new” mean in C++? I'm not familiar with C++

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.