直接上例子:
void updateUI() { if (dateTimePicker1.InvokeRequired) { dateTimePicker1.Invoke((MethodInvoker)delegate { dateTimePicker1.Enabled = true; dateTimePicker1.Checked = false; }); } else { dateTimePicker1.Enabled = true; dateTimePicker1.Checked = false; } }
如果不用匿名委托,那就像下面这样:
delegate void update(); void updateUI() { if (dateTimePicker1.InvokeRequired) { dateTimePicker1.Invoke(new update(() => { dateTimePicker1.Enabled = true; dateTimePicker1.Checked = false; })); } else { dateTimePicker1.Enabled = true; dateTimePicker1.Checked = false; } }