trophy 0
May 2025 109 posts
Sandbox.TaskSource.Create : api/Sandbox.TaskSource/Create
trophy 820
May 2023 32 posts
Creates a TaskSource whose entire lifetime is linked to the provided token.
If the token is canceled, all async operations using that TaskSource are canceled.


Example on how this differs from CreateLinkedTokenSource()
var cts = new CancellationTokenSource();
TaskSource ts = TaskSource.Create(cts.Token);

await ts.DelaySeconds(5); // if cts.Token is canceled, ts becomes invalid
 
var cts = TaskSource.CreateLinkedTokenSource();
TaskSource ts = new TaskSource();

await ts.DelaySeconds(5, cts.Token); // if cts.Token is cancelled only this delay is canceled
await ts.DelaySeconds(5) // Still Valid


people
Log in to reply
You can't reply if you're not logged in. That would be crazy.