Skip to content

Commit 29c4ebe

Browse files
authored
changed files by pdets auto publish service, publishid[8c20f672-fd11-45d7-a3bc-9acbf60e77f9] and do [publish].
1 parent c9ec9b4 commit 29c4ebe

13 files changed

+66
-62
lines changed

learn-pr/wwl-language/create-manage-events/1-introduction.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.introduction
2+
uid: learn.wwl.create-manage-events.introduction
33
title: Introduction
44
metadata:
55
title: Introduction
66
description: "Introduction to the module."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/2-examine-events-csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.examine-events-csharp
2+
uid: learn.wwl.create-manage-events.examine-events-csharp
33
title: Examine events in C#
44
metadata:
55
title: Examine events in C#
66
description: "Learn how events in C# enable communication between objects and streamline user interactions."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/3-declare-events-csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.declare-events-csharp
2+
uid: learn.wwl.create-manage-events.declare-events-csharp
33
title: Declare events in C#
44
metadata:
55
title: Declare events in C#
66
description: "Learn how to declare events in C# and use delegates to enable communication between components."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/4-subscribe-unsubscribe-events-csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.subscribe-unsubscribe-events-csharp
2+
uid: learn.wwl.create-manage-events.subscribe-unsubscribe-events-csharp
33
title: Subscribe and unsubscribe from events in C#
44
metadata:
55
title: Subscribe and unsubscribe from events in C#
66
description: "Learn how to manage event subscriptions and unsubscriptions to ensure efficient resource usage."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/5-explore-delegates-events-relationship-csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.explore-delegates-events-relationship-csharp
2+
uid: learn.wwl.create-manage-events.explore-delegates-events-relationship-csharp
33
title: Explore Delegates and Events Relationship in C#
44
metadata:
55
title: Explore Delegates and Events Relationship in C#
66
description: "Understand advanced concepts of delegates and events in C#, including custom event data, multicast delegates, and best practices."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/6-exercise-events-csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.exercise-events-csharp
2+
uid: learn.wwl.create-manage-events.exercise-events-csharp
33
title: 'Exercise: Implement events in C#'
44
metadata:
55
title: 'Exercise: Implement events in C#'
66
description: "Practice creating, subscribing to, and raising events in C# using delegates and custom event data classes."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/7-knowledge-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.knowledge-check
2+
uid: learn.wwl.create-manage-events.knowledge-check
33
title: Module assessment
44
metadata:
55
title: Module assessment
66
description: "Check what you've learned in this module."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/8-summary.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
### YamlMime:ModuleUnit
2-
uid: learn.wwl.review-intro-events.summary
2+
uid: learn.wwl.create-manage-events.summary
33
title: Summary
44
metadata:
55
title: Summary
66
description: "Summarize the key concepts covered in this module."
7-
ms.date: 04/22/2025
7+
ms.date: 04/23/2025
88
author: wwlpublish
99
ms.author: eric
1010
ms.topic: unit

learn-pr/wwl-language/create-manage-events/includes/2-examine-events-csharp.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Events let one part of a program inform other parts when something important occ
88

99
The following diagram illustrates the relationship between a publisher and subscribers in an event-driven model:
1010

11-
![Publisher and Subscriber](PublisherSubscriber.png "Diagram showing the relationship between a publisher and subscribers in an event-driven model.")
11+
![Publisher and Subscriber relationship](../media/PublisherSubscriber.png)
1212

1313
- The **publisher** raises an event when a specific action occurs, such as the selection of a button.
1414
- The **subscribers** handle the event by executing their respective event handler methods.
@@ -26,10 +26,11 @@ This model ensures that the publisher and subscribers remain loosely coupled, al
2626
```csharp
2727
public class Button
2828
{
29-
public event EventHandler Selected;
29+
public event EventHandler? Selected; // Nullable to indicate no subscribers initially
3030
3131
public void OnClick()
3232
{
33+
// If subscribers exist, ?.Invoke syntax triggers an event
3334
Selected?.Invoke(this, EventArgs.Empty);
3435
}
3536
}
@@ -42,8 +43,9 @@ button.Selected += (sender, e) => Console.WriteLine("Button Selected!");
4243
button.OnClick(); // Output: "Button Selected!"
4344
```
4445

45-
> [!NOTE]
46-
> Events provide a mechanism for decoupling components, allowing them to interact without tight dependencies.
46+
In this example, the `Selected` event is declared as `EventHandler?`, using a nullable reference type which explicitly indicates that the event might not have any subscribers, ensuring that the code handles such scenarios gracefully. The `?.Invoke` syntax further ensures that the event is only raised if there are subscribers, preventing potential `NullReferenceException` errors.
47+
48+
Lambda expressions (`=>`) are used in the subscription to define the event handler inline. Lambda expressions provide a concise and readable way to define event handlers, especially when the logic is simple and doesn't require a separate method.
4749

4850
## Delegates: The foundation of events
4951

@@ -67,7 +69,7 @@ public class Button
6769

6870
public void OnClick()
6971
{
70-
Clicked?.Invoke(this, EventArgs.Empty);
72+
Clicked?.Invoke(this, EventArgs.Empty);
7173
}
7274
}
7375
```

learn-pr/wwl-language/create-manage-events/includes/4-subscribe-unsubscribe-events-csharp.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class Program
3535
}
3636
```
3737

38+
Notice the previous code demonstrates how to subscribe to an event using the `+=` operator. The `Clicked` event is triggered from the `OnClick` method, and the `Button_Clicked` method handles the event. The `?.Invoke` syntax ensures the event is only raised if there are subscribers.
39+
3840
## Unsubscribing from events
3941

4042
Unsubscribing from an event involves detaching a method from the event using the `-=` operator. Unsubscribing events is important to prevent memory leaks, especially when the event publisher has a longer lifetime than the subscriber.
@@ -72,9 +74,11 @@ public class Program
7274
}
7375
```
7476

77+
Examination of this code shows how to unsubscribe from an event using the `-=` operator. After unsubscribing, the event handler is no longer invoked when the event is raised.
78+
7579
## Managing subscriptions dynamically
7680

77-
In some scenarios, you need to dynamically add or remove event handlers based on specific conditions. Removeing event handlers dynamically can be useful for managing complex workflows or ensuring that only relevant handlers are attached at any given time.
81+
In some scenarios, you need to dynamically add or remove event handlers based on specific conditions. Removing event handlers dynamically can be useful for managing complex workflows or ensuring that only relevant handlers are attached at any given time.
7882

7983
**Example: Dynamic subscription management**
8084

@@ -117,9 +121,11 @@ public class Program
117121
}
118122
```
119123

124+
In this example, code contains dynamically managed event subscriptions. The `isSubscribed` flag ensures that the handler is added or removed based on specific conditions.
125+
120126
## Avoiding memory leaks
121127

122-
Memory leaks can occur when event handlers aren't unsubscribed, especially if the event publisher outlives the subscriber. To avoid this, always unsubscribe from events when they're no longer needed.
128+
Memory leaks can occur when event handlers aren't unsubscribed, especially if the event publisher outlives the subscriber. To avoid memory leaks, always unsubscribe from events when they're no longer needed.
123129

124130
**Best practices for avoiding memory leaks:**
125131

@@ -152,6 +158,8 @@ public class Subscriber : IDisposable
152158
}
153159
```
154160

161+
This code example highlights how to unsubscribe from events in the `Dispose` method. This approach ensures that event handlers are properly removed, preventing memory leaks when the object is disposed.
162+
155163
## Summary
156164

157165
By understanding how to subscribe and unsubscribe from events, you can ensure efficient resource usage and avoid common pitfalls like memory leaks. Proper event management is essential for building robust and maintainable applications.

0 commit comments

Comments
 (0)