4

What's the difference between check InvokeRequired and call Invoke method for a control and for the parent form if I want to deal with the control from another thread?

if (theForm.InvokeRequired)
    Invoke(...)

Or

if (myControl.InvokeRequired)
   myControl.Invoke(...)

From MSDN:

The Invoke method searches up the control's parent chain until it finds a control or form that has a window handle if the current control's underlying window handle does not exist yet.

Homam
  • 23,263
  • 32
  • 111
  • 187

1 Answers1

7

These two have the same effect. You can assume the form and the control were created on the same thread.

Tim Robinson
  • 53,480
  • 10
  • 121
  • 138
  • 1
    Technically it is possible for this not to be the case. Very rare, but Windows does support pinvoking SetParent() to break that rule. Adobe Acrobat Reader does this for example. The AxHost wrapper for it is however still associated with the UI thread. Winforms will fight you tooth and nail to stop you from doing this. You can win. – Hans Passant Nov 11 '10 at 15:40