public async Task DownloadFiles(string path, CancellationToken token)
{
if (path == string.Empty)
return;
using (var wc = new WebClient())
using (token.Register(wc.CancelAsync))
{
wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
foreach (var fileName in downloadProvider.Files)
{
CreateNeccessaryDirs(path + @"\" + fileName.Value);
if (File.Exists(path + @"\" + fileName.Value))
{
continue;
}
prevDownloadedSize = 0L;
StartDownload?.Invoke(this, new StartDownloadFileArgs { FileName = fileName.Value });
stopwatch.Restart();
await wc.DownloadFileTaskAsync(new Uri(master_url + "/" + fileName.Key), path + @"\" + fileName.Value);
stopwatch.Stop();
}
}
ProgressChanged?.Invoke(this, new Events.DownloadProgressChangedEventArgs() { NewPercentage = 100 });
}
var cts = new CancellationTokenSource();
await d.DownloadFiles(SettingsFolder, cts );
static readonly string[] SizeSuffixes =
{ "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
Изначально это исключение было создано в этом стеке вызовов:
[Внешний код]
Launcher.Game.Downloader.OnProgressChanged() в Downloader.cs
Launcher.Game.Downloader.Wc_DownloadProgressChanged(object, System.Net.DownloadProgressChangedEventArgs) в Downloader.cs
[Внешний код]
private void OnProgressChanged()
{
Events.DownloadProgressChangedEventArgs eventInfo;
eventInfo = new Events.DownloadProgressChangedEventArgs() { NewPercentage = GetPercentage(),
Speed = Math.Round(double.Parse(speed)), DownloadedSize = currentDownloadedSize, AllSize = downloadProvider.Size };
ProgressChanged?.Invoke(this, eventInfo);
}