C#实现程序的版本升级更新

时间:2022-03-21 05:34:01

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Threading; using System.Net; using System.Xml; using Update; namespace UpdateTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); checkUpdate(); } public void checkUpdate() { SoftUpdate app = new SoftUpdate(Application.ExecutablePath, "BlogWriter"); app.UpdateFinish += new UpdateState(app_UpdateFinish); try { if (app.IsUpdate && MessageBox.Show("检查到新版本,是否更新?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Thread update = new Thread(new ThreadStart(app.Update)); update.Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } void app_UpdateFinish() { MessageBox.Show("更新完成,,请重新启动程序!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }