How to call asynchronous method from synchronous method in C#?

后端 未结 15 1041
星月不相逢
星月不相逢 2020-11-21 06:27

I have a public async void Foo() method that I want to call from synchronous method. So far all I have seen from MSDN documentation is calling async methods via

15条回答
  •  别那么骄傲
    2020-11-21 06:39

    I'm not 100% sure, but I believe the technique described in this blog should work in many circumstances:

    You can thus use task.GetAwaiter().GetResult() if you want to directly invoke this propagation logic.

提交回复
热议问题