子线程调用Timer控件问题
我的主线程是主窗体,
在子线程中触发主窗体的控件Timer开始计时,
怎么实现??
请高人指点!!
------解决方案--------------------参考如下的代码:
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(this.someMethod);
th.Start();
}
private delegate void somedel();
private void someMethod()
{
if (this.InvokeRequired)
{
somedel sd = new somedel(this.someMethod);
this.Invoke(sd);
return;
}
this.timer1.Interval = 500;
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
System.Console.WriteLine(DateTime.Now);
}