Skip to content

Commit cd69606

Browse files
authored
Update consuming-the-task-based-asynchronous-pattern.md (#32114)
* Update consuming-the-task-based-asynchronous-pattern.md - I think it is better to highlight the note at line 93: "Cancellation requests may be initiated from any thread." - At line 146 we're talking about the same method as another overloaded version but in fact is the same overload method. * Update consuming-the-task-based-asynchronous-pattern.md Fixed linter error on line 94
1 parent 2b52afd commit cd69606

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ var cts = new CancellationTokenSource();
9090
cts.Cancel();
9191
```
9292

93-
Cancellation requests may be initiated from any thread.
93+
> [!IMPORTANT]
94+
> Cancellation requests may be initiated from any thread.
9495
9596
You can pass the <xref:System.Threading.CancellationToken.None%2A?displayProperty=nameWithType> value to any method that accepts a cancellation token to indicate that cancellation will never be requested. This causes the <xref:System.Threading.CancellationToken.CanBeCanceled%2A?displayProperty=nameWithType> property to return `false`, and the called method can optimize accordingly. For testing purposes, you can also pass in a pre-canceled cancellation token that is instantiated by using the constructor that accepts a Boolean value to indicate whether the token should start in an already-canceled or not-cancelable state.
9697

@@ -142,7 +143,7 @@ public async void button1_Click(object sender, EventArgs e)
142143
}
143144
```
144145

145-
Some of these <xref:System.Threading.Tasks.Task.Run%2A> methods, such as the <xref:System.Threading.Tasks.Task.Run%28System.Func%7BSystem.Threading.Tasks.Task%7D%29?displayProperty=nameWithType> overload, exist as shorthand for the <xref:System.Threading.Tasks.TaskFactory.StartNew%2A?displayProperty=nameWithType> method. Other overloads, such as <xref:System.Threading.Tasks.Task.Run%28System.Func%7BSystem.Threading.Tasks.Task%7D%29?displayProperty=nameWithType>, enable you to use await within the offloaded work, for example:
146+
Some of these <xref:System.Threading.Tasks.Task.Run%2A> methods, such as the <xref:System.Threading.Tasks.Task.Run%28System.Func%7BSystem.Threading.Tasks.Task%7D%29?displayProperty=nameWithType> overload, exist as shorthand for the <xref:System.Threading.Tasks.TaskFactory.StartNew%2A?displayProperty=nameWithType> method. This overload enable you to use await within the offloaded work, for example:
146147

147148
```csharp
148149
public async void button1_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)