I have some async code that I would like to add a CancellationToken to. However, there are many implementations where this is not needed so I would like to have a d
It turns out that the following works:
Task DoStuff(...., CancellationToken ct = default(CancellationToken))
...or:
Task DoStuff(...., CancellationToken ct = default) // C# 7.1 and later
which, according to the documentation, is interpreted the same as CancellationToken.None:
You can also use the C#
default(CancellationToken)statement to create an empty cancellation token.