private void createNextDownload() { QueueElement elt = getFirstNotCompletedElement(); if (string.IsNullOrEmpty(elt.Url)) { return; } downloader = new HttpDownloader(elt.Url, elt.Destination); downloader.DownloadCompleted += downloader_DownloadCompleted; downloader.DownloadProgressChanged += downloader_DownloadProgressChanged; downloader.StartAsync(); currentElement = elt; queuePaused = false; startEventRaised = false; }
/// <summary> /// Deletes the queue element at the given index /// </summary> /// <param name="index">The index of the element that will be deleted</param> public void Delete(int index) { if (elements[index].Equals(currentElement) && downloader != null) { downloader.Cancel(); currentElement = new QueueElement() { Url = "" }; } elements.RemoveAt(index); if (!queuePaused) { createNextDownload(); } }
private void downloader_DownloadCompleted(object sender, EventArgs e) { if (QueueElementCompleted != null) { QueueElementCompleted(this, new QueueElementCompletedEventArgs(this.CurrentIndex, currentElement)); } for (int i = 0; i < elements.Count; i++) { if (elements[i].Equals(currentElement)) { elements[i] = new QueueElement() { Id = elements[i].Id, Url = elements[i].Url, Destination = elements[i].Destination, Completed = true }; break; } } createNextDownload(); }