I have an asynchronous method:
public async Task<Foo> GetFooAsync();
And I need its synchronous version. Something like this:
public Foo GetFoo();
I do not really want to totally rewrite code of GetFooAsync
and I would like to do something such as
public Foo GetFoo()
{
return GetFooAsync().GetAwaiter().GetResult();
}
Is it good idea or this method has any unobvious problems? As I know if I use GetFooAsync().Result
in synchronous context I may face with deadlock. But what about GetFooAsync().GetAwaiter().GetResult()
?