Lets assume that I have worker threads that increment a value on some control. Since an invoke is required, all the increments need to be done on the GUI thread. For that I use BeginInvoke.
My question is:
Can a race condition break the increment of the control, because multiple worker threads all invoked on the GUI thread simultaniously (and the increment itself someControl.Value += value;
is obviously not atomic)?
Or to put it the opposite:
Is one Invoke guaranteed to be finished before another one will be handled?
delegate void valueDelegate(int value);
private void IncrementValue(int value)
{
if (InvokeRequired)
{
BeginInvoke(new valueDelegate(IncrementValue),value);
}
else
{
someControl.Value += value;
}
}
Thank you!