为什么这个任务直接从WaitingForActivation转到RanToCompletion?

时间:2016-09-27 09:10:46

标签: c# async-await task

我在LINQPad中运行以下代码:

void Main()
{
    Task x = TestAsync();

    do
    {
        Thread.Sleep(200);
        Console.WriteLine(x.Status);
    } while (x.Status != TaskStatus.RanToCompletion);
}

public async static Task TestAsync()
{
    await Task.Delay(1000);
    return;
}

输出结果为:

WaitingForActivation
WaitingForActivation
WaitingForActivation
WaitingForActivation
RanToCompletion

为什么直接从WaitingForActivation转到RanToCompletion?为什么它显然永远不会处于Running状态?

0 个答案:

没有答案