diff --git a/xml/System.Threading/CancellationTokenSource.xml b/xml/System.Threading/CancellationTokenSource.xml index a470c54577f..7f35190b0c5 100644 --- a/xml/System.Threading/CancellationTokenSource.xml +++ b/xml/System.Threading/CancellationTokenSource.xml @@ -378,26 +378,30 @@ Communicates a request for cancellation. - will be notified of the cancellation and will transition to a state where returns true. + will be executed. +The associated is notified of the cancellation and transitions to a state where returns true. + +Any callbacks or cancelable operations registered with the are executed, if they haven't already been executed by a previous call to . Subsequent calls to won't execute the same callback again unless reregistered. (Avoid multiple calls to , because the intent of such code is often unclear.) - We recommend that cancelable operations and callbacks registered with not throw exceptions. +Callbacks are executed synchronously in LIFO order. - This overload of Cancel will aggregate any exceptions thrown into an , such that one callback throwing an exception will not prevent other registered callbacks from being executed. +We recommend that cancelable operations and callbacks registered with not throw exceptions. + +This overload of Cancel aggregates any exceptions thrown into an , such that one callback throwing an exception will not prevent other registered callbacks from being executed. - Calling this method has the same effect as calling [`Cancel(false)`](xref:System.Threading.CancellationTokenSource.Cancel(System.Boolean)). +Calling this method has the same effect as calling [`Cancel(false)`](xref:System.Threading.CancellationTokenSource.Cancel(System.Boolean)). ## Examples - The following example uses a random number generator to emulate a data collection application that reads 10 integral values from eleven different instruments. A value of zero indicates that the measurement has failed for one instrument, in which case the operation should be cancelled and no overall mean should be computed. - To handle the possible cancellation of the operation, the example instantiates a object that generates a cancellation token which is passed to a object. The object in turn passes the cancellation token to each of the tasks responsible for collecting readings for a particular instrument. The method is called to ensure that the mean is computed only after all readings have been gathered successfully. If a task has not because it has been cancelled, the call to the method throws an exception. +The following example uses a random number generator to emulate a data collection application that reads 10 integral values from eleven different instruments. A value of zero indicates that the measurement has failed for one instrument, in which case the operation should be cancelled and no overall mean should be computed. - :::code language="csharp" source="~/snippets/csharp/System.Threading/CancellationToken/Overview/cancel1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Threading/CancellationToken/Overview/cancel1.vb" id="Snippet1"::: +To handle the possible cancellation of the operation, the example instantiates a object that generates a cancellation token which is passed to a object. The object in turn passes the cancellation token to each of the tasks responsible for collecting readings for a particular instrument. The method is called to ensure that the mean is computed only after all readings have been gathered successfully. If a task has not because it has been cancelled, the call to the method throws an exception. + +:::code language="csharp" source="~/snippets/csharp/System.Threading/CancellationToken/Overview/cancel1.cs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/System.Threading/CancellationToken/Overview/cancel1.vb" id="Snippet1"::: ]]> @@ -453,18 +457,21 @@ if exceptions should immediately propagate; otherwise, . Communicates a request for cancellation, and specifies whether remaining callbacks and cancelable operations should be processed if an exception occurs. - will be notified of the cancellation and will transition to a state where returns `true`. - - Any callbacks or cancelable operations registered with the will be executed. Callbacks will be executed synchronously in LIFO order. + not throw exceptions. +The associated is notified of the cancellation and transitions to a state where returns `true`. + +Any callbacks or cancelable operations registered with the are executed, if they haven't already been executed by a previous call to . Subsequent calls to won't execute the same callback again unless reregistered. (Avoid multiple calls to , because the intent of such code is often unclear.) - If `throwOnFirstException` is `true`, an exception will immediately propagate out of the call to , preventing the remaining callbacks and cancelable operations from being processed. +Callbacks are executed synchronously in LIFO order. + +We recommend that cancelable operations and callbacks registered with not throw exceptions. + +If `throwOnFirstException` is `true`, an exception will immediately propagate out of the call to , preventing the remaining callbacks and cancelable operations from being processed. - If `throwOnFirstException` is `false`, this overload will aggregate any exceptions thrown into an , such that one callback throwing an exception will not prevent other registered callbacks from being executed. +If `throwOnFirstException` is `false`, this overload aggregates any exceptions thrown into an , such that one callback throwing an exception will not prevent other registered callbacks from being executed. ]]> @@ -632,8 +639,8 @@ Communicates a request for cancellation asynchronously. A task that will complete after cancelable operations and callbacks registered with the associated have completed. - The associated will be notified of the cancellation and will synchronously transition to a state where returns . - Any callbacks or cancelable operations registered with the will be executed asynchronously, with the returned representing their eventual completion. + The associated is notified of the cancellation and synchronously transitions to a state where returns . + Any callbacks or cancelable operations registered with the will be executed asynchronously, with the returned representing their eventual completion. Callbacks registered with the token should not throw exceptions. However, any such exceptions that are thrown will be aggregated into an , such that one callback throwing an exception will not prevent other registered callbacks from being executed.