namespace 多线程1
{
public partial class Form1 : Form
{
bool flag = true;
public Form1()
{
InitializeComponent();
drn = new dgrunNumber(runNumber);
}
private void btnStar_Click(object sender, EventArgs e)
{
Thread thread = new Thread(run);
thread.IsBackground = true;
thread.Start();
}
private void run()
{
Random rd = new Random();
while (flag)
{
int i = rd.Next(10);
this.Invoke(drn, i.ToString());
}
}
private void runNumber(string msg)
{
lab1.Text = msg;
}
delegate void dgrunNumber(string msg);
dgrunNumber drn = null;