CancellationTokenSource.TryReset Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Attempts to reset the CancellationTokenSource to be used for an unrelated operation.
public:
bool TryReset();
public bool TryReset ();
member this.TryReset : unit -> bool
Public Function TryReset () As Boolean
Returns
true
if the CancellationTokenSource has not had cancellation requested and could have its state reset to be reused for a subsequent operation; otherwise, false
.
Remarks
TryReset() is intended to be used by the sole owner of the CancellationTokenSource when it is known that:
- The operation with which the CancellationTokenSource was used has completed.
- No-one else will attempt to cancel it.
- Any remaining registrations are erroneous.
Upon a successful reset, such registrations will no longer be notified for any subsequent cancellation of the
CancellationTokenSource; however, if any component still holds a reference to this
CancellationTokenSource either directly or indirectly via a CancellationToken
handed out from it, polling via their reference will show the current state any time after the reset as
it's the same instance. Usage of TryReset() concurrently with requesting cancellation is not
thread-safe and may result in TryReset() returning true
even if cancellation was already requested. Also, it may result
in registrations not being invoked as part of the concurrent cancellation request.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기