public void DownloadAndAdd(IEnumerable <string> urls, string outputFileName) { Active = true; // loop through and download each foreach (var url in urls) { // check we are still a going concern Console.WriteLine(url); if (Active) { DownloadAndAdd(url, outputFileName); } else { // return without invoking MultipleDownloadsCompleted return; } } // all done, invoke event MultipleDownloadsCompleted.Invoke(this, new EventArgs()); // turn off the sign Active = false; }
public void Download(IEnumerable <string> urls) { Active = true; // after each single download, turn the stile DownloadFileCompleted += delegate(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { auto.Set(); }; // loop through and download each foreach (var url in urls) { // check we are still a going concern if (Active) { Download(url); // block until download finished/5 mins (turning async into sync) auto.WaitOne(300000); } else { // fire cancelled event if (DownloadsCancelled != null) { DownloadsCancelled.Invoke(this, new EventArgs()); } // return without invoking MultipleDownloadsCompleted return; } } // all done, invoke event if (MultipleDownloadsCompleted != null) { MultipleDownloadsCompleted.Invoke(this, new EventArgs()); } // turn off the sign Active = false; }