Example #1
0
        public void Start()
        {
            System.Net.ServicePointManager.DefaultConnectionLimit = 4;

            progresslabels[progresslabels.Length - 1].Text    = "";
            progresslabels[progresslabels.Length - 1].Visible = true;
            lock (downloadQueue)
            {
                if (downloadQueue.Count > 0)
                {
                    for (int i = 0; i < progressbars.Length; i++)
                    {
                        if (progressbars[i].Tag == null)
                        {
                            CommonFileDownload dd = downloadQueue.Dequeue();
                            dd.ProgressBar   = progressbars[i];
                            dd.ProgressLabel = progresslabels[i];
                            dd.StartDownload();
                            if (downloadQueue.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public void UpdateQueue(CommonFileDownload d)
        {
            lock (downloadQueue)
            {
                d.Finished              = true;
                d.ProgressBar.Tag       = null;
                d.ProgressBar.Value     = 0;
                d.ProgressLabel.Visible = false;

                if (downloadQueue.Count > 0 && !cancellationTokenSource.IsCancellationRequested)
                {
                    CommonFileDownload newd = downloadQueue.Dequeue();
                    newd.ProgressBar   = d.ProgressBar;
                    newd.ProgressLabel = d.ProgressLabel;
                    newd.StartDownload();
                }
            }
            finishedDownloads++;
            progresslabels[progresslabels.Length - 1].Text = $"{finishedDownloads}/{downloads.Count} files finished";

            if (finishedDownloads == downloads.Count && !cancellationTokenSource.IsCancellationRequested)
            {
                DownloadsFinishedForm downloadsFinishedForm = new DownloadsFinishedForm(downloadFolderPath, "All downloads are finished!");
                downloadsFinishedForm.Show();
            }
        }