If I Invoke a method onto the UI Thread is it searilized by the Windows message queue and subsequently doesn’t need to be re-entrant?
private void CalledFromWorkerThread()
{
//changed from 'InvokeRequired' Anti-Pattern
this.Invoke((Action) (() => _counter++; /* Is this ok? */ ));
}
Clarification: It is only the UI thread that will be accessing _counter.
What you have is fine, assuming
_counteris only accessed by the UI thread.If two threads call your
CalledFromWorkerThread, then _counter will be properly incremented and thread-safe with what you have.