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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:57:57+00:00 2026-06-01T23:57:57+00:00

I am trying to create a thread which will continuously check for changes to

  • 0

I am trying to create a thread which will continuously check for changes to a value, then visually show that change in a PictureBox located in my GUI.

What I actually wrote is a bit more complicated, so I simplified it while keeping the basic idea, I would be happy to provide clarification if this isn’t enough:

public class CheckPictures
{
    PictureBox update;
    List<String> check;

    public CheckPictures(PictureBox anUpdate, List<String> aCheck)
    {
        update = anUpdate;
        check = aCheck;
    }

    public void start()
    {
        while(true)
        {
            if (aCheck[0] == "Me")
            {
                update.Image = Image.fromFile("");
            }
        }
    }
}

static int Main(string[] args)
{ 
    List<String> picturesList = new List<String>();

    CheckPictures thread1 = new CheckPictures(PictureBox1, picturesList);
    Thread oThread1 = new Thread(thread1.start));
}

What I want it to do is dynamically change the picture in PictureBox1 if I were to add the string “Me” to pictureList. The above code isn’t working like I’d hoped. I had thought that by passing the actual PictureBox and List, any changes to the List elsewhere is the program would be caught by the thread. So my first question is: Is this possible? And if so, what change would I need to make to my code to achieve it?

  • 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-01T23:57:58+00:00Added an answer on June 1, 2026 at 11:57 pm

    You definetely do not want to do an infinite loop, this will just consume cpu:

    while(true)
    {
          if (aCheck[0] == "Me")
          {
                update.Image = Image.fromFile("");
          }
     }
    

    I think you should look into the CountdownLatch class.

    public class CountdownLatch
      {
        private int m_remain;
        private EventWaitHandle m_event;
    
        public CountdownLatch(int count)
        {
          m_remain = count;
          m_event = new ManualResetEvent(false);
        }
    
        public void Signal()
        {
          // The last thread to signal also sets the event.
          if (Interlocked.Decrement(ref m_remain) == 0)
            m_event.Set();
        }
    
        public void Wait()
        {
          m_event.WaitOne();
        }
      }
    

    The basic idea here is that you need to stop execution on your thread for some time and resume whenever a certain condition has been met (perhaps on another thread).

    In other words, you will have a counter, decrement its value on certain condition and whenever it goes to zero you fire your event, execute some code and then start over (stop execution and wait for the counter to go to zero).

    In your case you could set the counter to 1 and decrement its value whenever you’ve set aCheck[0] = "Me"; This way you don’t waste CPU.

    Pseudo code:

    Initialize counter:

    CountdownLatch latch = new CountdownLatch(1);
    

    Make thread wait:

    public void start()
    {
        while(true)
        {
          latch.Wait(); //execution stops
          {
              //execution resumes once the latch counter is zero.
              if (aCheck[0] == "Me")  //double check you have what you need
              {
                  update.Image = Image.fromFile("");
                  latch = new CountdownLatch(1); //reset if you need to do it again
              }
          }
        }
    }
    

    Whenever your condition is met (i.e. aCheck[0] = "Me";) signal your latch:

    latch.Signal();
    

    this last line will make the thread resume execution. Good stuff.

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

Sidebar

Related Questions

I am trying to create a dll which will create a thread when you
I am trying to create a regular expression which will look for a email
I am trying to create a UDP listener that will listen on a separate
I'm trying to create a sub-class of the JButton component that will enable or
I'm trying to create a program which will visualize different sorting algorithms by drawing
I am trying to create a simple web form which will give me a
I am trying to create a soundboard program which will play sounds using the
I'm trying to create a python server that will serve calls from outer source
I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
I am trying to create this QT gui using a thread but no luck.

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.