What concepts do I have to know to access data between two threads safely?
Right now I'm using a delegate method and Invoke to call a function in the
other thread that handles the data. This method seems a little bulky and I
read that it can have problems as it stalls.
for example, heres how I update the text to a textbox and the a status bar
label
this.Invoke(new TextDelegate(UpdateTextBox2), text);
this.Invoke(new TextDelegate(UpdateStatus), new object[] { "Finished" });
I call this function which is inside the forms class which is attached to an
event in another class which is controled by a thread.
i.e.
I have two classes, One is a the main gui form and the other is a
"computation" class that does things that take a long time.
In the computation class I have an event that the computation class calls
when it is finished with its computation to let the form know it can then
display the results. I then attach a function to this event that is in the
forms class so I can use the data in the form directly.
The methodology I use seems kinda bulky and probably has issues.
The project is located at
http://www.jonslaughter.com/files/SerialRow.rar
if anyone is interested.
-----
Also, something that I'm not sure about is when I attach a function to a
thread, when I call thread.Start(); thread.Stop(); Thread.Start(); Each time
on Thread.Start() does it re enter the function? (I'm using abort which I
read somewhere was bad)
Basically what I want call the function to compute and when it finished
display the result but the computation must be done in the background. I
also want to be able to "abort" the computation and restart it with
different parameters because the user might want to change something.
Anyways, any help would be appreciated. I guess I have to get a good book on
threading as I can't seem to find any coherent information the net.
Thanks,
Jon