using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UpdateUI();
Thread workthread = new Thread(new ThreadStart(this.DoSomething));
workthread.Start();
}
private delegate void InvokeMethodDelegate();
void DoSomething()
{
System.Threading.Thread.Sleep(5 * 1000);
this.Invoke(new InvokeMethodDelegate(this.UpdateUI));
}
void UpdateUI()
{
textBox1.Text = textBox1.Text + DateTime.Now.ToLongTimeString() + "\r\n";
}
}
}
C# 线程更新 UI
最新推荐文章于 2020-12-16 23:19:49 发布