多线程这样写
lblDateValue.Invoke(new Action(() => { lblDateValue.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fffffff"); })); 报错了。
解决办法:
public static class ControlInvoker
{
public static void Invoke(Control ctl, MethodInvoker method)
{
if (!ctl.IsHandleCreated)
return;
if (ctl.IsDisposed)
return;
if (ctl.InvokeRequired)
{
ctl.Invoke(method);
}
else
{
method();
}
}
}
ControlInvoker.Invoke(this, delegate
{
lblDateValue.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fffffff");
});