Wait for a void async method

后端 未结 6 1272
终归单人心
终归单人心 2020-12-02 07:20

How can I wait for a void async method to finish its job?

for example, I have a function like below:

async void LoadBlahBlah()
{
    awa         


        
6条回答
  •  Happy的楠姐
    2020-12-02 08:12

    Best practice is to mark function async void only if it is fire and forget method, if you want to await on, you should mark it as async Task.

    In case if you still want to await, then wrap it like so await Task.Run(() => blah())

提交回复
热议问题