您的位置:首页 > 产品设计 > UI/UE

C# 线程更新 UI

2011-11-30 15:15 274 查看
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";
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: