public Task <byte[]> DownloadImageAsyncIncorrect(string url) { var http = new HttpClientStub(); return(Task.Run(() => http.GetByteArrayAsync(url))); }
// Correct implementation: it does not do CPU-bound operations so we do not use Task.Run to call http.GetByteArrayAsync // because it already starts a new task internally. // This method calls GetByteArrayAsync but does it whithout await so there is no async keyword. public Task <byte[]> DownloadImageAsync(string url) { var http = new HttpClientStub(); return(http.GetByteArrayAsync(url)); }