Wait for a void async method

MBZ picture MBZ · Nov 30, 2012 · Viewed 128.1k times · Source

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

for example, I have a function like below:

async void LoadBlahBlah()
{
    await blah();
    ...
}

now I want to make sure that everything has been loaded before continuing somewhere else.

Answer

Rohit Sharma picture Rohit Sharma · Nov 30, 2012

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())