2

I have a function that isn't async and as a result I can't use await. In that function I call a function that's async.

My coworker suggested I use:

private void Foo()
{
   var _ = BarAsync();
}

This way however has the disadvantage that I don't get notified when the function throws errors. Is there a better way to call the function? I don't care whether or not the function gets executed asyncronly.

Christian
  • 25,249
  • 40
  • 134
  • 225

1 Answers1

0
var result = BarAsync()?.Result;

Or

var runningTask = BarAsync();
runningTask.Wait();
var result = runningTask?.Result;
Liam
  • 27,717
  • 28
  • 128
  • 190