Skip to content

is not disposing of CancellationTokenSource in ToCancellationToken a problem? #4611

@SimonCropp

Description

@SimonCropp

given CancellationTokenSource is disposable. is it a problem to not have it being disposed?

public static class TimeSpanExtensions
{
  public static CancellationToken ToCancellationToken(this TimeSpan timeout)
  {
    var cts = new CancellationTokenSource(timeout);
    return cts.Token;
  }
}

https://learn.microsoft.com/en-us/dotnet/standard/threading/cancellation-in-managed-threads

You should be sure to call the CancellationTokenSource.Dispose method when you have finished using the cancellation token source to free any unmanaged resources it holds.

Metadata

Metadata

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions