public DownloadResultList DownloadWithoutDialog(DownloadRequestList objDownloadRequests) { if (objDownloadRequests == null) { throw new ArgumentNullException("objDownloadRequests", "A valid non-null DownloadRequestList is expected"); } _objJobResult = null; IEnumerable <ITask> objTasks = objDownloadRequests.GetTasks(); Job objDownloadJob = new Job(objTasks); objDownloadJob.JobEnd += new Job.OnJobEndDelegate(objDownloadJob_JobEnd); objDownloadJob.Start(); objDownloadJob.Wait(); DownloadResultList objDownloadResults = new DownloadResultList(); if (_objJobResult != null) { foreach (ITaskResult objTaskResult in _objJobResult.TaskResults) { DownloadResult objDownloadResult = (DownloadResult)objTaskResult; objDownloadResults.Add(objDownloadResult); } } return(objDownloadResults); }
private void DownloadThread() { Thread.Sleep(10); this.ThreadSafe(new MethodInvoker(delegate() { listViewStatus.Items.Clear(); foreach (DownloadRequest objDownloadRequest in _objDownloadRequests) { string strFileName = Path.GetFileName(objDownloadRequest.Source); ListViewItem objListViewItem = new ListViewItem(objDownloadRequest.Destination); objListViewItem.SubItems.Add("Queued"); listViewStatus.Items.Add(objListViewItem); } buttonCancel.Enabled = _objDownloadDialogSettings.AllowCancel; buttonPauseContinue.Enabled = _objDownloadDialogSettings.AllowPause; this.Refresh(); })); _intTaskIndex = 0; _intTaskCount = _objDownloadRequests.Count; _objJobResult = null; IEnumerable <ITask> objTasks = _objDownloadRequests.GetTasks(); _objJob = new Job(objTasks); _objJob.TaskBegin += new Job.OnTaskBeginDelegate(objDownloadJob_TaskBegin); _objJob.TaskEnd += new Job.OnTaskEndDelegate(objDownloadJob_TaskEnd); _objJob.JobEnd += new Job.OnJobEndDelegate(objDownloadJob_JobEnd); _objJob.TaskProgressChanged += new Job.TaskProgressChangedDelegate(objDownloadJob_TaskProgressChanged); _objJob.Start(); _objJob.Wait(); _objDownloadResults = new DownloadResultList(); if (_objJobResult != null) { _objDownloadResults = new DownloadResultList(_objJobResult.TaskResults); } Thread.Sleep(10); this.ThreadSafe(new MethodInvoker(delegate() { this.Close(); })); }