private void OnUpdateStatusChanged(object sender, UpdateStatusChangedEventArgs e) { Invoke(new Action(() => { switch (e.Status) { case UpdateStatus.Start: _infoLabel.Text = e.Message; break; case UpdateStatus.GetLatestReleaseCompleted: _updateInfoTextBox.Text = e.Message; _infoLabel.Text = "获取更新信息完成"; _updateButton.Enabled = true; break; case UpdateStatus.FileDownloading: _updateProgressBar.Style = ProgressBarStyle.Blocks; _infoLabel.Text = e.Message; if (e.Message.LastIndexOf(':') > 0) { var p = e.Message.Substring(e.Message.LastIndexOf(':') + 1).TrimEnd('%'); _updateProgressBar.Value = int.Parse(p); } break; case UpdateStatus.Update: _infoLabel.Text = e.Message; break; case UpdateStatus.Done: _infoLabel.Text = e.Message; Application.DoEvents(); var ds = MessageBox.Show("是否运行更新后的程序?", "更新完成", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ds == DialogResult.Yes) { StartParent(); } Application.Exit(); break; case UpdateStatus.Error: MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } Application.DoEvents(); })); }
protected virtual void OnUpdateStatusChanged(UpdateStatusChangedEventArgs e) { UpdateStatusChanged?.Invoke(this, e); }