C# Несколько загрузок с веб-клиентом - PullRequest
0 голосов
/ 21 февраля 2020

У меня есть список загрузки в текстовый файл. (http://launcher.dryadmu.com/Update/ArchiveList.txt) И он проверяет, изменился ли crc32, и только затем загружает файл клиенту, проблема в том, что при увеличении списка это занимает слишком много времени. Класс загрузки:

 class FileDownloader
{
    private static int curFile;
    private static long lastBytes;
    private static long currentBytes;

    private static Stopwatch stopWatch = new Stopwatch();

    public static void DownloadFile()
    {
        if (Globals.OldFiles.Count <= 0)
        {
            Common.ChangeStatus("CHECKCOMPLETE");
            Common.UpdateCompleteProgress(100);
            Common.StartGame();
            return;
        }

        if (curFile >= Globals.OldFiles.Count)
        {
            Common.ChangeStatus("DOWNLOADCOMPLETE");
            Common.StartGame();
            return;
        }

        if (Globals.OldFiles[curFile].Contains("/"))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(Globals.OldFiles[curFile]));
        }

        WebClient webClient = new WebClient();

        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);

        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);

        stopWatch.Start();

        webClient.DownloadFileAsync(new Uri(Globals.ServerURL + Globals.OldFiles[curFile]), Globals.OldFiles[curFile]);
    }

    private static void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        currentBytes = lastBytes + e.BytesReceived;

        Common.ChangeStatus("DOWNLOADFILE", Globals.OldFiles[curFile], curFile.ToString(), Globals.OldFiles.Count.ToString());

        Common.UpdateCompleteProgress(Computer.Compute(Globals.completeSize + currentBytes));

        Common.UpdateCurrentProgress(e.ProgressPercentage, Computer.ComputeDownloadSpeed(e.BytesReceived, stopWatch));

    }

    private static void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        lastBytes = currentBytes;

        Common.UpdateCurrentProgress(100, 0);

        curFile++;

        stopWatch.Reset();

        DownloadFile();
    }
}

Я не мог понять, как добавить DownloadFileTaskAsyn c. Любая помощь будет оценена. Thx

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...