0

Good day, I implemented the download system on the webclient, it was simple, I wanted to do it on AltoHttp, nothing works, do you have any solutions

using (WebClient wc = new WebClient())
{
    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 });
}
Fildor
  • 14,510
  • 4
  • 35
  • 67
  • 1
    Hi! Your question is quite open ended. It is impossible to come up with a perfect suggestion because every client library is different in nature / has some advantages/disadvantages. For example, take a look at https://stackoverflow.com/questions/20530152/deciding-between-httpclient-and-webclient - this is a discussion about webclient vs httpclient. – Amogh Sarpotdar Jul 08 '22 at 08:46
  • This one is relevant too - https://stackoverflow.com/questions/45711428/download-file-with-webclient-or-httpclient?rq=1 – Amogh Sarpotdar Jul 08 '22 at 08:46
  • @AmoghSarpotdar So I presented my solution, is it generally possible to redo it? For at the moment the download needs to be done like mine – Сергей Маерович Jul 08 '22 at 09:05
  • 2
    This [Remark in the MS Docs](https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient?view=net-6.0#remarks) makes the decision easy for me: _"We don't recommend that you use the WebClient class for new development. Instead, use the System.Net.Http.HttpClient class."_ – Fildor Jul 08 '22 at 09:12
  • Yes, WebCLient is not recommended by MS for several reasons. If its just question of downloading files you can also use https://stackoverflow.com/questions/14192993/how-to-use-httpwebrequest-response-to-download-a-binary-exe-file-from-a-web-s - the HttpWebRequest class. Also, what you are doing is not wrong. Its just that MS may choose to remove WebClient implementation in future, merge it somewhere etc, thats why they dont recommend it. – Amogh Sarpotdar Jul 08 '22 at 10:45

0 Answers0