public void StartDownLoad() { try { //lblProgress.Text = "正在下载更新文件,请稍后..."; this.Invoke(_UpdateProgressDelegate, new Object[] { "正在下载更新文件,请稍后..." }); if (StrUrl == "GetDownloadUrlError") //获得url错误,推出程序 { _ItemExitDelegateEvent(); return; } System.Diagnostics.Trace.WriteLine(StrUrl); _rusumeDownload.downLoad(FileName, StrUrl); this.Invoke(_UpdateProgressDelegate, new Object[] { "" }); } catch (System.ObjectDisposedException) { } catch (Exception ex) { if (ex.Message == "ThreadAbort") { _ItemExitDelegateEvent(); return; } else { _MsgBoxShowDelegateEvent("下载过程中出现错误,请检查网络并重新下载。",true); //_ItemExitDelegateEvent(); return; } } finally { _rusumeDownload = null; } //下载完毕,自动执行 Process.Start(FileName, null); _ItemExitDelegateEvent(); ExitProgram(); }
private void UpdateForm_Load(object sender, EventArgs e) { _rusumeDownload = new RusumeDownload(); _rusumeDownload.CLabeText += new RusumeDownload.CLabelTextDelegate(_rusumeDownload_CLabeText); _rusumeDownload.CProgressBarMaximum += new RusumeDownload.CProgressBarMaximumDeletate(_rusumeDownload_CProgressBarMaximum); _rusumeDownload.CProgressBarValue += new RusumeDownload.CProgressBarValueDeletate(_rusumeDownload_CProgressBarValue); _UpdateProgressDelegate = new UpdateProgressDelegate(UpdateProgress); _CProgressBarValue = new CProgressBarValue(ProgressBarValue); _CProgressBarMaximum = new CProgressBarMaximum(ProgressBarMaximum); _CLabeText = new CLabeText(LabeText); _ItemExitDelegateEvent += new ItemExitDelegate(UpdateForm__ItemExitDelegateEvent); _MsgBoxShowDelegateEvent += new MsgBoxShowDelegate(UpdateForm__MsgBoxShowDelegateEvent); try { if (File.Exists(FileName)) { File.Delete(FileName); } } catch (Exception ex) { _MsgBoxShowDelegateEvent("删除老文件错误," + ex.Message,true); ExitProgram(); } _Thread = new Thread(new ThreadStart(StartDownLoad)); _Thread.Start(); }