The two code segments below lead to different outcomes – they’re intended to wait for a long-running task to complete. Completion of the task is signaled by the function ‘taskCompleted’. The task is not under direct control of the code that is waiting for it.
The intention is to just wait, while not locking up the UI.
while (!taskCompleted())
{
await Task.Delay(200);
}
vs
await Task.Run(async () =>
{
while (!taskCompleted())
{
await Task.Delay(200);
}
});
The second leads to the correct outcome, but I fail to see how it’s functionally different from the first.