using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Update { public partial class Form1 : Form { private readonly static string mainAppPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), ".."); private readonly static string mainAppFile = Path.Combine(mainAppPath, "dajiaoyan.exe"); public Form1() { InitializeComponent(); Task.Factory.StartNew(async () => { await Task.Delay(2000); await Services.Update.UpdateApplication( "http://static.yuansiwei.com/app/dajiaoyan/ocr/dajiaoyan.zip", mainAppPath, UpdateProgress, AfterUpdate); }); } public void UpdateProgress(string step, int nowP, int maxP) { Task.Factory.StartNew(() => { BeginInvoke(new Action(() => { stepProgressLabel.Text = step; stepProgressBar.Minimum = 0; stepProgressBar.Maximum = maxP; stepProgressBar.Value = nowP; })); }); } public void AfterUpdate(bool ok, string info) { BeginInvoke(new Action(() => { if (ok) { MessageBox.Show(info, "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); try { Task.Delay(2000); Process.Start(mainAppFile); } catch { } } else { MessageBox.Show(info, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } Close(); })); } } }