跨线程访问
private void ShowIOStatus(bool isOpen) { if (IOStatusLB.InvokeRequired) { IOStatusLB.Invoke(new Action(() => { IOStatusLB.Text = isOpen ? "已连接" : "未连接"; IOStatusLB.BackColor = isOpen ? Color.Green : Color.Red; if (isOpen) { ResetBT.Enabled = true; StartBT.Enabled = true; } else { ResetBT.Enabled = false; StartBT.Enabled = false; } })); } else { IOStatusLB.Text = isOpen ? "已连接" : "未连接"; IOStatusLB.ForeColor = isOpen ? Color.Green : Color.Red; if (isOpen) { ResetBT.Enabled = true; StartBT.Enabled = true; } else { ResetBT.Enabled = false; StartBT.Enabled = false; } } }
主要是这个语句
if (IOStatusLB.InvokeRequired) { IOStatusLB.Invoke(new Action(() => { //内容 })); }
开心是个奢饰的东西

浙公网安备 33010602011771号