I was looking at Control.BeginInvoke method and I didn’t quite get what it means when it says:
Executes a delegate asynchronously on the thread that the control’s
underlying handle was created on.
What is control's underlying handle? What does it do?
Controls have “thread affinity” – meaning there is a demand that they are only directly manipulated (or even inspected, except a few specific properties such as
InvokeRequired) by the thread that created them (commonly called the UI thread). The handle is simply the abstraction between the OS control and the .NET control.What this actually does is place a message on the windows message loop, that is picked up by the UI thread (which owns the control), causing your delegate to be invoked on the UI thread. This means it is allowed to talk to the control. This is useful if you are currently on a background thread (maybe an async callback or
BackgroundWorker), and need to update the UI.