Use CancellationToken.UnsafeRegister in a few more places by stephentoub · Pull Request #37551 · dotnet/corefx (original) (raw)

stephentoub

CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs:

@stephentoub

@azure-pipelines

Azure Pipelines successfully started running 2 pipeline(s), but failed to run 2 pipeline(s).

@ViktorHofer

@chcosta any idea why this is frequently happening?

/eng/pipelines/corefx-base.yml: Could not find /eng/common/templates/job/job.yml in repository self hosted on https://api.github.com using commit 2bc9594. GitHub reported the error, "Not Found"

PRs are failing because of this.

@chcosta

There's a long mail thread about this with no satisfactory resolution. I'll forward it to you.

@stephentoub

@azure-pipelines

Azure Pipelines successfully started running 4 pipeline(s).

bartonjs

@stephentoub

CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs:

picenka21 pushed a commit to picenka21/runtime that referenced this pull request

Feb 18, 2022

@stephentoub

…efx#37551)

CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs:

Commit migrated from dotnet/corefx@b1a1bfa