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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:29:31+00:00 2026-05-21T18:29:31+00:00

How do you implement busy waiting in a not total inefficient way? I am

  • 0

How do you implement busy waiting in a not total inefficient way? I am facing the issue that I can load the data of my model only in a pull manner, which means I have to invoke getXYZ() methods in a continuous way.

This has to happen not fast enough for user interaction, but fast enought, that when a state in the GUI is changed, the model can be noticed and the new state is received by the getXYZ() methods.

My approach simply be:

while (c.hasChanged()) {
   Thread.sleep(500);
}
updateData();

Are there better mechanisms?

  • 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-21T18:29:32+00:00Added an answer on May 21, 2026 at 6:29 pm

    Your problem seems to be solvable with Threading.

    In WPF you can do:

    Thread t = new Thread((ThreadStart)delegate() {
       while (true) {
          Thread.sleep(500);
          if (c.hasChanged())
              Dispatcher.Invoke((Action)delegate() {updateData();});
       }
    
    }).Start();
    

    In WinForms

    Thread t = new Thread((ThreadStart)delegate() {
       while (true) {
          Thread.sleep(500);
          // this must derive from Control
          if (c.hasChanged())
              this.Invoke((Action)delegate() {updateData();});
       }
    
    }).Start();
    

    There may be missing parameters to Invoke (which is needed to execute the code on the calling UI thread) but I’m writing this from my brain so no intellisense at disposal 😀

    In .NET 4 you can use TaskFactory.StartNew instead of spawning a thread by yourself.
    In .Net <= 4, you could use the TreadPool for the thread.
    However I recall you need this to be run at once because you expect it to be there checking as soon as possible and the thread pool won’t assure you that (it could be already full, but not very likely:-).
    Just don’t do silly things like spawning more of them in a loop!

    And inside the thread you should put a check like

    while (!Closing)
    

    so that the thread can finish when you need it without having to resort to bad things like t.Abort();
    An when exiting put the Closing to true and do a t.Join() to close the checker thread.

    EDIT:

    I forgot to say that the Closing should be a bool property or a VOLATILE boolean, not a simple boolean, because you won’t be ensured that the thread could ever finish (well it would in case you are closing the application, but it is good practice to make them finish by your will). the volatile keyword is intended to prevent the (pseudo)compiler from applying any optimizations on the code that assume values of variables cannot change

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

Sidebar

Related Questions

To implement data access code in our application we need some framework to wrap
I'm about to implement a feature in our application that allows the user to
I'm trying to implement a data compression idea I've had, and since I'm imagining
I'm busy creating a metaclass that replaces a stub function on a class with
We implement some triggers which perform some operations with insert data before committing them
I want to be able to design/implement a splash screen that originally goes over
Task: implement paging of database records suitable for different RDBMS. Method should work for
I need to implement a Diff algorithm in VB.NET to find the changes between
I am trying to implement string unescaping with Python regex and backreferences, and it
I need to implement version control, even for just the developing I do at

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.