I'd like to wrap the WebClient.DownloadFileAsync method, which is actually non blocking, into a method which returns a Task and can be awaited until the download is completed.
I understand the logic behind suscribing to the DownloadFileCompleted event, as explained here (and in plenty other posts) but I'd like to wrap it into something more user friendly. And my knowledge of asynchronous programming is quite superficial.
The best I can think of is to wrap DownloadFile method (synchronous) into a Task and returns it , but I've read many times that wrapping a synchronous method onto a an asynchronous one is not a good practice
return Task.Run(() =>client.DownloadFile(fileUri, localPath));
It's actually the first time I meet an async method which is non awaitable, is there a reason why it has been thought this way?
Thanks