Skip to content

Commit 542cdb3

Browse files
authored
Add clarifications about Control.Invoke behavior when an EventHandler is used (#9317)
1 parent 1e8f571 commit 542cdb3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xml/System.Windows.Forms/Control.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8235,7 +8235,12 @@ MyControl.Font = New Font(MyControl.Font, _
82358235
> [!NOTE]
82368236
> In addition to the <xref:System.Windows.Forms.Control.InvokeRequired%2A> property, there are four methods on a control that are thread safe: <xref:System.Windows.Forms.Control.Invoke%2A>, <xref:System.Windows.Forms.Control.BeginInvoke%2A>, <xref:System.Windows.Forms.Control.EndInvoke%2A>, and <xref:System.Windows.Forms.Control.CreateGraphics%2A> if the handle for the control has already been created. Calling <xref:System.Windows.Forms.Control.CreateGraphics%2A> before the control's handle has been created on a background thread can cause illegal cross thread calls. For all other method calls, you should use one of the invoke methods to marshal the call to the control's thread.
82378237

8238-
The delegate can be an instance of <xref:System.EventHandler>, in which case the sender parameter will contain this control, and the event parameter will contain <xref:System.EventArgs.Empty?displayProperty=nameWithType>. The delegate can also be an instance of <xref:System.Windows.Forms.MethodInvoker>, or any other delegate that takes a void parameter list. A call to an <xref:System.EventHandler> or <xref:System.Windows.Forms.MethodInvoker> delegate will be faster than a call to another type of delegate.
8238+
The delegate can be an instance of <xref:System.EventHandler>, in which case the parameters will depend on the `args` value:
8239+
- If no parameters are passed, the sender parameter will contain this control and the event parameter will contain <xref:System.EventArgs.Empty?displayProperty=nameWithType>.
8240+
- When a single parameter is passed, the sender parameter will contain the first args element and the event parameter will contain <xref:System.EventArgs.Empty?displayProperty=nameWithType>.
8241+
- If more than one parameter is passed, the sender parameter will contain the first element from `args`, and the <xref:System.EventArgs> parameter will contain the second element.
8242+
8243+
A call to an <xref:System.EventHandler> or <xref:System.Windows.Forms.MethodInvoker> delegate will be faster than a call to another type of delegate.
82398244

82408245
> [!NOTE]
82418246
> An exception might be thrown if the thread that should process the message is no longer active.

0 commit comments

Comments
 (0)