【发布时间】:2009-04-07 10:56:28
【问题描述】:
要访问我的表单上的备忘录,我使用以下代码
public string TextValue
{
set
{
if (this.Memo.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate
{
this.Memo.Text += value + "\n";
});
}
else
{
this.Memo.Text += value + "\n";
}
}
}
我想使用相同的代码来启用/禁用我的计时器,但是没有属性 InvokeRequired 用于计时器。
public int Timer
{
set
{
if (this.timer.InvokeRequired) //?? No such thing
{
this.Invoke((MethodInvoker)delegate
{
if (value == 1)
this.timer.Enabled = true;
else
this.timer.Enabled = false;
});
}
else
{
if (value == 1)
this.timer.Enabled = true;
else
this.timer.Enabled = false;
}
}
}
如何从不同的线程启用计时器?
【问题讨论】:
标签: c# winforms multithreading timer