using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace test
{
public partial class Form1 : Form
{
private delegate void MyUpdate(string str);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.IsBackground = true;
t.Start();
}
void ThreadProc()
{
for (int i = 0; i < 10; i++)
{
Runtime_UpdateUI(i.ToString());
Thread.Sleep(1000);
}
}
private void Runtime_UpdateUI(string str)
{
if (this.InvokeRequired)
{
MyUpdate update = new MyUpdate(Runtime_UpdateUI);
this.Invoke(update, new object[] { str });
}
else
{
label1.Text = str;
}
}
}
}