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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:56:54+00:00 2026-06-13T14:56:54+00:00

I have a very contrived issue. Imagine I have a class which has one

  • 0

I have a very contrived issue.

Imagine I have a class which has one method only and one field. Like:

public class WhereAmI
{
    public int Number = 0;
    public void Looping()
    {
         for (int i = 0; i < 100; i++)
        {
            Number = i;
            Sleep(10000);
        }
    }
}

I call it from another class in the normal way you would expect

WhereAmI wai = new WhereAmI();
wai.Looping();
int CurrentNumber = wai.Number;

What I want is a way to see what number I’m currently up to and display that on screen. I’ve tried similar to the above but this won’t work because the compiler won’t move past the wai.Loopping() method until it’s complete.

I assume I have to do this on a new thread and then get into the world of cross threading? I then thought my design must be wrong and I’ve over complicating this!

Any one care to pass their opinion or suggestion on this?

Thank you

  • 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-13T14:56:54+00:00Added an answer on June 13, 2026 at 2:56 pm

    Assuming this code is running on the UI thread it could just update the UI directly within the loop. However if don’t want to mix UI code with your business logic (which is a good idea) then yes you will need to run this processing on another thread and have the UI thread either inspect this object, or preferably get event notifications as task progresses.

    You should probably look at using BackgroundWorker to handle the processing. This class makes it simpler to farm out processing tasks like this and contains logic to support progress indicators.

    The sample code in the MSDN article shows how you can set a lot of this up via drag and drop onto the design surface (assuming you’re using WinForms), and how to link the BackgroundWorker to a progress bar.

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

Sidebar

Related Questions

I have a very large, spread out class that is essentially a very contrived
I have a localization issue. One of my industrious coworkers has replaced all the
I have very simple window where I have 2 buttons - one for cancel,
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have a very similar problem to the one described at [JasperReport parameters works
In this very contrived example, I have an array with 3 elements that I'm
i have very serious problem if any tech expert can help...thank you in advance..
I have very simple piece of code. The goal is when i input four-digit
I have very very big html page/data. I need to fetch data under h1
I have very strange problem while I am submitting a practice problem on codechef.

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.