3

I am using the excellent library from Steven called AsyncEx to help me baby-step the transition of an old codebases across to the async world.

The docs say..

class Program
{
  static async Task<int> AsyncMain()
  {
    ..
  }

  static int Main(string[] args)
  {
    return AsyncContext.Run(AsyncMain);
  }
}

When calling a method with a different signature, should I be doing..

var blah = AsyncContext.Run(() => MyMethodAsync(myvar));

or specify the async/wait in the call?

var blah = AsyncContext.Run( async () => await MyMethodAsync(myvar));

or, doesn't it matter?

Sam
  • 535
  • 5
  • 14

1 Answers1

3

I now believe that this is the same as Return Task or Await Questions and therefore Rene's answer there will be correct

poorly summarized here as -- bit more overhead in await for the compiler, but basically the same at runtime.

Sam
  • 535
  • 5
  • 14
  • 1
    Correct. I have a [blog post on the subject](https://blog.stephencleary.com/2016/12/eliding-async-await.html), but the conclusion is it doesn't really matter in this case. – Stephen Cleary Nov 17 '21 at 01:17