0%

CSharp复习-子线程更新MainForm

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Thread update;
public Form1()
{
InitializeComponent();
update = new Thread(UpdateFunc);
}

//子线程更新主界面Label值
void UpdateFunc()
{
while (true)
{
Invoke(()=> label1.Text = DateTime.Now.ToString("HH:mm:ss"));
Invoke((string x)=> label1.Text = x + DateTime.Now.ToString("HH:mm:ss"),"时间:");
Thread.Sleep(500);
}
}