异步层次结构

Asynchronous hierarchy

如果我有一个异步方法,在参数中包含一个异步方法和一个none异步方法。

先运行哪个方法?

示例:

await ExampleMethod(
            Func<Task>: await Example.SomeMethod(), 
            Func<IEnumerable<T>> Example.SomeOtherMethod()
            );

Which method would run first?

异步方法调用没有什么神奇之处。他们 start executing synchronously, just like any other method(正如我在我的博客中描述的那样)。此外,异步根本不会影响参数评估的顺序。

所以,这段代码:

await ExampleMethod(await Example.SomeMethod(), Example.SomeOtherMethod());

与此代码基本相同:

var parameter1 = await Example.SomeMethod();
var parameter2 = Example.SomeOtherMethod();
await ExampleMethod(parameter1, parameter2);