Correct usage for Nito.AsyncEx.AsyncContext.Run

Viewed 445

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?

1 Answers

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.

Related