If I had an asynchronous method that contained an asynchronous method and a none asynchronous method in the parameters.
Which method would run first?
Example:
await ExampleMethod(
Func<Task>: await Example.SomeMethod(),
Func<IEnumerable<T>> Example.SomeOtherMethod()
);
CodePudding user response:
Which method would run first?
There's nothing magic about asynchronous method invocations. They start executing synchronously, just like any other method (as I describe on my blog). Also, asynchrony doesn't impact the order of argument evaluation at all.
So, this code:
await ExampleMethod(await Example.SomeMethod(), Example.SomeOtherMethod());
is essentially the same as this code:
var parameter1 = await Example.SomeMethod();
var parameter2 = Example.SomeOtherMethod();
await ExampleMethod(parameter1, parameter2);