Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions xml/System/EventHandler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,22 @@
<format type="text/markdown"><![CDATA[

## Remarks
The event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:

- A delegate that identifies the method that provides the response to the event.
The event model in .NET is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:

- Optionally, a class that holds the event data, if the event provides data.
- A delegate that identifies the method that provides the response to the event.
- Optionally, a class that holds the event data, if the event provides data.

The delegate is a type that defines a signature, that is, the return value type and parameter list types for a method. You can use the delegate type to declare a variable that can refer to any method with the same signature as the delegate.

The standard signature of an event handler delegate defines a method that does not return a value. This method's first parameter is of type <xref:System.Object> and refers to the instance that raises the event. Its second parameter is derived from type <xref:System.EventArgs> and holds the event data. If the event does not generate event data, the second parameter is simply the value of the <xref:System.EventArgs.Empty?displayProperty=nameWithType> field. Otherwise, the second parameter is a type derived from <xref:System.EventArgs> and supplies any fields or properties needed to hold the event data.

The <xref:System.EventHandler> delegate is a predefined delegate that specifically represents an event handler method for an event that does not generate data. If your event does generate data, you must use the generic <xref:System.EventHandler%601> delegate class.
The <xref:System.EventHandler> delegate is a predefined delegate that specifically represents an event handler method for an event that does not generate data. If your event does generate data, you must use the generic <xref:System.EventHandler`1> delegate class.

To associate the event with the method that will handle the event, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate.

For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/).



## Examples
The following example shows an event named `ThresholdReached` that is associated with an <xref:System.EventHandler> delegate. The method assigned to the <xref:System.EventHandler> delegate is called in the `OnThresholdReached` method.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/eventsoverview/cpp/programwithdata.cpp" id="Snippet6":::
:::code language="csharp" source="~/snippets/csharp/System/EventArgs/Overview/programwithdata.cs" id="Snippet6":::
:::code language="fsharp" source="~/snippets/fsharp/System/EventArgs/Overview/programwithdata.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/eventsoverview/vb/module1withdata.vb" id="Snippet6":::

]]></format>
</remarks>
<altmember cref="T:System.EventHandler`1" />
Expand All @@ -114,6 +104,5 @@
<related type="Article" href="/dotnet/visual-basic/programming-guide/language-features/events/">Events (Visual Basic)</related>
<related type="Article" href="/dotnet/csharp/programming-guide/events/">Events (C# Programming Guide)</related>
<related type="Article" href="/dotnet/fsharp/language-reference/members/events/">Events (F#)</related>
<related type="Article" href="https://learn.microsoft.com/previous-versions/windows/apps/hh758286(v=win.10)">Events and routed events overview (Windows store apps)</related>
</Docs>
</Type>
14 changes: 6 additions & 8 deletions xml/System/EventHandler`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,25 @@
<format type="text/markdown"><![CDATA[

## Remarks
The event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:

- A delegate that refers to a method that provides the response to the event.
The event model in .NET is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:

- Optionally, a class that holds the event data, if the event provides data.
- A delegate that refers to a method that provides the response to the event.
- Optionally, a class that holds the event data, if the event provides data.

The delegate is a type that defines a signature, that is, the return value type and parameter list types for a method. You can use the delegate type to declare a variable that can refer to any method with the same signature as the delegate.

The standard signature of an event handler delegate defines a method that does not return a value. This method's first parameter is of type <xref:System.Object> and refers to the instance that raises the event. Its second parameter is derived from type <xref:System.EventArgs> and holds the event data. If the event does not generate event data, the second parameter is simply the value of the <xref:System.EventArgs.Empty?displayProperty=nameWithType> field. Otherwise, the second parameter is a type derived from <xref:System.EventArgs> and supplies any fields or properties needed to hold the event data.

The <xref:System.EventHandler%601> delegate is a predefined delegate that represents an event handler method for an event that generates data. The advantage of using <xref:System.EventHandler%601> is that you do not need to code your own custom delegate if your event generates event data. You simply provide the type of the event data object as the generic parameter.
The <xref:System.EventHandler`1> delegate is a predefined delegate that represents an event handler method for an event that generates data. The advantage of using <xref:System.EventHandler`1> is that you don't need to code your own custom delegate if your event generates event data. You simply provide the type of the event data object as the generic parameter.

To associate the event with the method that will handle the event, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate.

For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/).



## Examples
The following example shows an event named `ThresholdReached`. The event is associated with an <xref:System.EventHandler%601> delegate.

The following example shows an event named `ThresholdReached`. The event is associated with an <xref:System.EventHandler`1> delegate.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/eventsoverview/cpp/programwithdata.cpp" id="Snippet6":::
:::code language="csharp" source="~/snippets/csharp/System/EventArgs/Overview/programwithdata.cs" id="Snippet6":::
Expand All @@ -125,6 +124,5 @@
<related type="Article" href="/dotnet/visual-basic/programming-guide/language-features/events/">Events (Visual Basic)</related>
<related type="Article" href="/dotnet/csharp/programming-guide/events/">Events (C# Programming Guide)</related>
<related type="Article" href="/dotnet/fsharp/language-reference/members/events/">Events (F#)</related>
<related type="Article" href="https://learn.microsoft.com/previous-versions/windows/apps/hh758286(v=win.10)">Events and routed events overview (Windows store apps)</related>
</Docs>
</Type>
Loading