通过ConfigureAwait进行线程切换(false)

时间:2018-12-12 10:05:51

标签: c# .net multithreading asynchronous

以下测试是否总是通过?如果没有,情况是什么?

    [Test]
    public async Task Test()
    {
        var before = Thread.CurrentThread.ManagedThreadId;

        await Task.Delay(1).ConfigureAwait(continueOnCapturedContext: false);

        var after = Thread.CurrentThread.ManagedThreadId;

        Assert.AreNotEqual(before, after);
    }

0 个答案:

没有答案