Handle UI updates from a background thread in WinForms
UI controls in WinForms possess "thread affinity," indicating that they may only be accessed or updated securely from the thread that instantiated them, usually the primary UI thread.
Accessing directly from a background thread will lead to an InvalidOperationException. To refresh the UI from a background thread, it is necessary to marshal the invocation to the UI thread utilising Control.Summon or Regulate.InitiateInvoke.
- Regulation.InvokeRequired: A boolean attribute that indicates true if the current thread differs from the thread that instantiated the control.
- Regulation.Invoke(Delegate method): Executes the designated delegate synchronously on the thread that created the control. The invoking thread is halted until the UI thread completes the execution of the delegate.
- Regulation.BeginInvoke(Delegate method): Asynchronously executes the designated delegate on the thread that created the control. The invoking thread remains unblocked and proceeds with its execution.