Hi, First I would like to say I am VERY new to programming and still dont understand alot. Please be patient with me.
Im trying to have have an object on my UI refresh on a seperate thread. I have read about 100 tutorials about multithreading and still dont completely understand it. Im using zedgraph and need to refresh it on a seperate thread because it messes up my timings.
Here is why, I need to acurately have a process timed and the refresh or invalidate of zedgraph is slow and fluctuates. Im using the stopwatch and a tight loop (I know its bad) as my timer because I need accurate timing and thread.sleep isnt accurate below @20ms, Im working with between 5ms and 70ms.
Im confused with delegates and invoking, I mean completely lost. I dont understand how invoke works and how to use it and same with delegates. ANY help would be appreciated.
Thansk John
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Mar 11, 2010, 4:54 PM EST
Let's assume you need to update a textbox called textBox1 in a form. Let's also assume that your other thread is executing within the form's class, although I get the impression that is not true. Please explain how the other thread is able to access the form if the thread is not in the form's class. If you don't understand, then say so.
Add the following as a member of the from:
Also add the following method to the form: Then when you need to update textBox1 from the thread, call SetText with the string for textBox1.
John Wiberg3 reputationPosted Mar 12, 2010, 2:16 PM EST
The code you included is the best example Ive seen so far. The threads are in the same class, Is it more advisable to create another discrete thread or use the backroundworker dowork? The second thread will/should remain active during the time the main thread is active.
Im sorry if I confuse you, im really new to programming windows programs, Im an embedded c programmer and a lot of these things are new to me.
Sam HobbsRank #107 · 20.5K reputationPosted Mar 12, 2010, 10:42 PM EST
Add the following as a member of the from:
Also add the following method to the form:
Cody5 reputationPosted Apr 1, 2010, 2:54 PM EDT
private void SetValue(object property, object value, Control control)
{
if (control.InvokeRequired)
{
this.Invoke(new SetValueCallback(SetText), new object[] { property, value, control });
}
else
{
property = value;
}
}