日期:2014-05-17 浏览次数:21337 次
Thread th = new Thread((ThreadStart)delegate() { test(); }); th.Start(); public void test() { int i=0; while (i<100000) { this.Invoke ( (MethodInvoker)delegate() { label1.Text = i.ToString(); } ); i += 100; } }
------解决方案--------------------
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int number = 0;
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.Text = "按钮" + number;
number++;
}
private void button2_Click(object sender, EventArgs e)
{
Thread th = new Thread(delegate()
{
NewMethod();
});
th.Start();
}
private static void NewMethod()
{
for (int i = 0; i < 10000; i++)
{
Console.WriteLine(i);
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}