M
mgorbach
Im writing a program that does monte carlo simulation and im having
trouble figuring out how to get the threading model right. I have a
simulation class which contains all simulation data and methods to run
the simulation for an x number of sweeps. An instance of this object is
declared in the class of my main form. The main form handles graphics
(it shows the particles moving on the form). I am now trying to split
up the work so that the UI thread is separate from the thread running
the simulation prgoram. I will also probably be adding a form to
allowing viewing of the same data by chart, so i need the simualtion
object to be accessible from multiple forms. The simulation object has
an event which is triggered when the simulation moves a particle, with
the form listening for that event and updating itself. The problem is
when i run the simulation in a separate thread i get exceptions when
trying to access graphics objects for drawing (because im accessing UI
elements from a nonUI thread).
Can someone help me out to figure out a good structure for the program?
trouble figuring out how to get the threading model right. I have a
simulation class which contains all simulation data and methods to run
the simulation for an x number of sweeps. An instance of this object is
declared in the class of my main form. The main form handles graphics
(it shows the particles moving on the form). I am now trying to split
up the work so that the UI thread is separate from the thread running
the simulation prgoram. I will also probably be adding a form to
allowing viewing of the same data by chart, so i need the simualtion
object to be accessible from multiple forms. The simulation object has
an event which is triggered when the simulation moves a particle, with
the form listening for that event and updating itself. The problem is
when i run the simulation in a separate thread i get exceptions when
trying to access graphics objects for drawing (because im accessing UI
elements from a nonUI thread).
Can someone help me out to figure out a good structure for the program?