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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:30:18+00:00 2026-06-15T02:30:18+00:00

I am going through this tutorial on how to perform some work in the

  • 0

I am going through this tutorial on how to perform some work in the background and in this piece of code I am confused as to why the message reading the file... is not displayed before the ReadTheFile(filename) method is called.

private void btnSelect_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.CheckFileExists = true;
    ofd.CheckPathExists = true;

    if (ofd.ShowDialog() == DialogResult.OK)
    {
        lblResults.Text = " ... reading the file ...";
        FileReader1 fr = new FileReader1();
        int numLines = fr.ReadTheFile(ofd.FileName);

        lblResults.Text = string.Format("We read {0} lines", numLines.ToString());
    }
}

The author explains it by saying the following, but it did not really get through to me.

Worse, even though we set the label’s Text property before we call ReadTheFile, the message loop doesn’t get a chance to process that change, and update the text, before we go out to lunch in ReadTheFile.

What does this mean? Can this be explained in simpler terms?

  • 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-15T02:30:19+00:00Added an answer on June 15, 2026 at 2:30 am

    Worse, even though we set the label’s Text property before we call ReadTheFile, the message loop doesn’t get a chance to process that change, and update the text, before we go out to lunch in ReadTheFile.

    Basically you are setting the text of label. However, you then start doing a “intensive” task that could take seconds, minutes, hours. As long as you are continuing to load the file and read the number of lines, the window will not update. That’s the point of doing it in a background thread. Let the main thread continue to paint the window and handle UI stuff while your background thread processes the file.

    I would continue with the tutorial. Once you get to the part where you start creating and running the background worker you may end up with one of those “Aha!” moments. =)

    You may also be interested in reading up on threads in general.

    http://www.codeproject.com/Articles/26148/Beginners-Guide-to-Threading-in-NET-Part-1-of-n

    http://www.techrepublic.com/article/a-beginners-guide-to-threading-in-c/1044970

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

Sidebar

Related Questions

I'm going through a Haskell tutorial and am given this piece of code to
I am going through a tutorial on XNA, and it uses this code: private
I was going through this tutorial http://www.schillmania.com/content/projects/javascript-animation-1/ and when I institute the code, I
I am going through this tutorial: http://blog.assimov.net/blog/2011/04/03/multi-file-upload-with-uploadify-and--carrierwave-on-rails-3/ One of the lines of code is:
I am going through a tutorial, and it showed this example code to make
I am going through this tutorial and I am a bit confused of about
I am going through this tutorial , but I already had Ruby 1.8.7 installed.
I am going through this tutorial about PDO and have come to the point
Trying to learn a bit about PDO and is going through this tutorial .
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore

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.