So let's say I have a method
async Task<int> GetStackOverflowAsync()
{
Task<int> longRunningCpuBoundTask = Task<int>.Run(() =>
{
// some long-running CPU-bound task that returns an int
})
.ConfigureAwait(continueOnCapturedContext: true);
return await longRunningCpuBoundTask;
}
and let's say the captured context is a UI thread that needs the int
. So I understand that Task.Run
offloads the long-running CPU-bound task to another thread, but I'm wondering which thread checks for the completion of that task.
I imagine what happens is like
UI Thread |- do UI stuff -||- check longRunningCpuBoundTask -||- do more UI stuff -||- check longRunningCpuBoundTask |- Start from we left off at the await -| longRunningCpuBoundTask Thread |------------------------------------------------------------ done! ---------------------------------------|
Can someone correct my understanding?