From 9b9d7b9ea9768c8379b865471c55b2a173ff629b Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Thu, 16 Apr 2020 19:04:22 +0200 Subject: [PATCH 1/3] Clarify thread-safe event raising --- .../language-reference/operators/member-access-operators.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/member-access-operators.md b/docs/csharp/language-reference/operators/member-access-operators.md index 13d333bfedddb..01600af509c2d 100644 --- a/docs/csharp/language-reference/operators/member-access-operators.md +++ b/docs/csharp/language-reference/operators/member-access-operators.md @@ -1,7 +1,7 @@ --- title: "Member access operators and expressions - C# reference" description: "Learn about C# operators that you can use to access type members." -ms.date: 03/31/2020 +ms.date: 04/17/2020 author: pkulikov f1_keywords: - "._CSharpKeyword" @@ -150,6 +150,8 @@ if (handler != null) } ``` +That is a thread-safe way to ensure that only a non-null `handler` is invoked. Because delegate instances are immutable, no thread can change the value referenced by the `handler` local variable. In particular, if the code executed by another thread unsubscribes from the `PropertyChanged` event and `PropertyChanged` becomes `null` before `handler` is invoked, the value referenced by `handler` remains unaffected. + ## Invocation expression () Use parentheses, `()`, to call a [method](../../programming-guide/classes-and-structs/methods.md) or invoke a [delegate](../../programming-guide/delegates/index.md). From 2012e12aafff46f881315803c78da11e4aed8e1a Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Fri, 17 Apr 2020 17:51:18 +0200 Subject: [PATCH 2/3] Update docs/csharp/language-reference/operators/member-access-operators.md Co-Authored-By: Bill Wagner --- .../language-reference/operators/member-access-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/member-access-operators.md b/docs/csharp/language-reference/operators/member-access-operators.md index 01600af509c2d..6624224e73a17 100644 --- a/docs/csharp/language-reference/operators/member-access-operators.md +++ b/docs/csharp/language-reference/operators/member-access-operators.md @@ -150,7 +150,7 @@ if (handler != null) } ``` -That is a thread-safe way to ensure that only a non-null `handler` is invoked. Because delegate instances are immutable, no thread can change the value referenced by the `handler` local variable. In particular, if the code executed by another thread unsubscribes from the `PropertyChanged` event and `PropertyChanged` becomes `null` before `handler` is invoked, the value referenced by `handler` remains unaffected. +That is a thread-safe way to ensure that only a non-null `handler` is invoked. Because delegate instances are immutable, no thread can change the value referenced by the `handler` local variable. In particular, if the code executed by another thread unsubscribes from the `PropertyChanged` event and `PropertyChanged` becomes `null` before `handler` is invoked, the value referenced by `handler` remains unaffected. The `?.` operator evaluates its left operand no more than once, guaranteeing that it cannot be changed to `null` after being verified as non-null. ## Invocation expression () From d54f7d447b3539e97258f4c8a4a86abe63f14e68 Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Fri, 17 Apr 2020 17:52:21 +0200 Subject: [PATCH 3/3] Minor update --- .../language-reference/operators/member-access-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/member-access-operators.md b/docs/csharp/language-reference/operators/member-access-operators.md index 6624224e73a17..b177ef03bfdfe 100644 --- a/docs/csharp/language-reference/operators/member-access-operators.md +++ b/docs/csharp/language-reference/operators/member-access-operators.md @@ -150,7 +150,7 @@ if (handler != null) } ``` -That is a thread-safe way to ensure that only a non-null `handler` is invoked. Because delegate instances are immutable, no thread can change the value referenced by the `handler` local variable. In particular, if the code executed by another thread unsubscribes from the `PropertyChanged` event and `PropertyChanged` becomes `null` before `handler` is invoked, the value referenced by `handler` remains unaffected. The `?.` operator evaluates its left operand no more than once, guaranteeing that it cannot be changed to `null` after being verified as non-null. +That is a thread-safe way to ensure that only a non-null `handler` is invoked. Because delegate instances are immutable, no thread can change the value referenced by the `handler` local variable. In particular, if the code executed by another thread unsubscribes from the `PropertyChanged` event and `PropertyChanged` becomes `null` before `handler` is invoked, the value referenced by `handler` remains unaffected. The `?.` operator evaluates its left-hand operand no more than once, guaranteeing that it cannot be changed to `null` after being verified as non-null. ## Invocation expression ()