Hi there,
I wanted a bit of advice on a program (a prototype) that I am trying
to write that uses threads. I will outline what I am attempting to
do, and if anyone has any advice on the way I am trying to work I
would be most grateful.
I am writing a windows forms application. This application defines a
class, lets call this myObject. I instanciate objects of this class
and store the myObjects in an ArrayList.
The main thread of this application will maintain the ArrayList of
myObjects. This could have new myObjects added, data changing for
myObjects or myObjects being removed.
I also have a groupbox on the main form. For each myObject I want to
have a PictureBox and a label to graphically rerpresent it on the
form. this will be of the order of a red picture or a green picture
depending onthe status of a myObject. I want these pictures / labels
to be updated in as close to realtime as possbile.
My current thinking for this is to use a separate thread that will be
in charge of drawing the devices to the page. So this thread would
continually cycle through the ArrayList of myObjects and either create
a PictureBox (if one doesn't already exist) or change the picture from
Red to Green if the status has changed, or do nothing if the status of
the myObject has not changed since it last redrew it.
The main reason I thought this could work would be that the worker
thread can simply draw the pictures it needs to. changing the
graphical view would be a simple process of adding / removing
myObjects to / from the ArrayList
Does this sound like a reasonable way to maintain this type of
structure?
I have been playing around with some varying levels of success so I
thought I should stop and think about this in more detail.
Am I going to hit conflict problems if my worker thread is trying to
update a picture based on a myObject and the myObject changes / gets
removed halfway through?
Can I stop and start the worker thread every time I need to make
changes to the ArrayList and restart it after, allowing it to catch
any changes?
Incidentally, my program does not affect the Status changes on a
myObject. That is something detected from outside my program and
checking the Status attribute of that myObject will cause it to give
the live Status.... so there is not really any simple way for me to
detect a change and redraw that object.
So.. I hope that all makes sense. If anyone has any advice then I
would be most grateful. I am starting to get a headache, so need to
take a step back and get high-level again.
Thanks
Mark.