async void when overriding

Viewed 719

I'm aware of the evils of async void methods but am not entirely sure of the best way of over coming the problem when overriding methods.

Say, I have the following code:

protected override async void PageRefreshed()
{
    BoundDataField = await LoadDataFromWeb();
}

I know this is a really bad thing to do, but what is the best solution for this?

  1. LoadDataFromWeb().ContinueWith(r => BoundDateField = r.Result);
  2. Task.Run(async ()=> await LoadDataFromWeb())).Wait;
  3. LoadDataFromWeb().Wait
  4. BoundDataField = LoadDataFromWeb.Result

I'm pretty sure that 3 & 4 are real no nos as they will be blocking the UI thread. Is there another solution I have missed?

1 Answers
Related