private async Task DownloadNeededFiles() { await Task.Run(() => { foreach (var fileUpdateInfo in FileUpdateInfos) { if (NeedUpdate(fileUpdateInfo)) { try { Logger.Trace("Downloading file: {0}", fileUpdateInfo.FileName); byte[] content = _restApi.DownloadFile(fileUpdateInfo.Url); content.SaveAs(fileUpdateInfo.LocalFilePath); Logger.Trace("Downloaded. Bytes count: {0}", content.Length); if (NeedUpdate(fileUpdateInfo)) { fileUpdateInfo.FileStatus = L("UpdateFailed"); } else { fileUpdateInfo.FileStatus = L("UpToDate"); } Logger.Trace("File status: {0}", fileUpdateInfo.FileStatus); FileUpdateInfos.Refresh(); } catch (Exception e) { fileUpdateInfo.FileStatus = L("UpdateFailed"); Logger.Error(e, "Downloading error."); } } else { fileUpdateInfo.FileStatus = L("UpToDate"); } } }); }