/
UpdateForm.cs
48 lines (46 loc) · 1.28 KB
/
UpdateForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace AutoUpdate
{
public partial class UpdateForm : Form
{
public delegate void UpdateUI(int step);//声明一个更新主线程的委托
public UpdateUI UpdateUIDelegate;
private UpdateWork work;
public UpdateForm(UpdateWork _work)
{
work = _work;
InitializeComponent();
UpdateUIDelegate = new UpdateUI((obj) =>
{
this.updateBar.Value = obj;
});
work.OnUpdateProgess += new UpdateWork.UpdateProgess((obj) =>
{
this.Invoke(UpdateUIDelegate, (int)obj);
});
}
private void UpdateForm_Load(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem((obj) =>
{
try
{
work.Do();
this.DialogResult = DialogResult.OK;
}
catch (Exception EX)
{
MessageBox.Show(EX.Message);
}
});
}
}
}