You create a task with Task.Run , which starts and forgets the actual task that you are returning from MyLoopTask .
Task.Run is redundant here. You can simply call MyLoopTask and use the task that it returns.
var t = MyLoopTask(200, ct);
If you still have reason to use Task.Run , you can do this by making sure that the delegate is waiting for the real task, waiting for it:
var t = Task.Run(async () => await MyLoopTask(200, ct));
source share