Skip to content

Commit 5a2b566

Browse files
committed
Explain semantics of multiple calls to CancellationTokenSource.Cancel
Also copy a line about LIFO semantics from one of the overloads, to unify the docs for each function.
1 parent 3b6ab82 commit 5a2b566

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

xml/System.Threading/CancellationTokenSource.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@
383383
## Remarks
384384
The associated <xref:System.Threading.CancellationToken> will be notified of the cancellation and will transition to a state where <xref:System.Threading.CancellationToken.IsCancellationRequested%2A> returns true.
385385
386-
Any callbacks or cancelable operations registered with the <xref:System.Threading.CancellationToken> will be executed.
387-
386+
Any callbacks or cancelable operations registered with the <xref:System.Threading.CancellationToken> will be executed, if they have not already been executed by a previous call to <xref:System.Threading.CancellationTokenSource.Cancel>. Subsequent calls to <xref:System.Threading.CancellationTokenSource.Cancel> will not execute the same callback again unless re-registered. (We recommend avoiding multiple calls to <xref:System.Threading.CancellationTokenSource.Cancel>, because the intent of such code is often unclear.)
387+
388+
Callbacks will be executed synchronously in LIFO order.
389+
388390
We recommend that cancelable operations and callbacks registered with <xref:System.Threading.CancellationToken> not throw exceptions.
389391
390392
This overload of Cancel will aggregate any exceptions thrown into an <xref:System.AggregateException>, such that one callback throwing an exception will not prevent other registered callbacks from being executed.
@@ -458,7 +460,9 @@
458460
## Remarks
459461
The associated <xref:System.Threading.CancellationToken> will be notified of the cancellation and will transition to a state where <xref:System.Threading.CancellationToken.IsCancellationRequested%2A> returns `true`.
460462
461-
Any callbacks or cancelable operations registered with the <xref:System.Threading.CancellationToken> will be executed. Callbacks will be executed synchronously in LIFO order.
463+
Any callbacks or cancelable operations registered with the <xref:System.Threading.CancellationToken> will be executed, if they have not already been executed by a previous call to <xref:System.Threading.CancellationTokenSource.Cancel>. Subsequent calls to <xref:System.Threading.CancellationTokenSource.Cancel> will not execute the same callback again unless re-registered. (We recommend avoiding multiple calls to <xref:System.Threading.CancellationTokenSource.Cancel>, because the intent of such code is often unclear.)
464+
465+
Callbacks will be executed synchronously in LIFO order.
462466
463467
We recommend that cancelable operations and callbacks registered with <xref:System.Threading.CancellationToken> not throw exceptions.
464468

0 commit comments

Comments
 (0)