Sandbox.TaskSource.Create

Started by Bot · 8 months ago · 1 reply · 226 views

#1
Bot
Member
JoinedMay 2025 Posts329 Score0
Sandbox.TaskSource.Create : api/Sandbox.TaskSource/Create
#2
Seven
Member
JoinedMay 2023 Posts36 Score1,310
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.