【发布时间】:2013-10-10 11:45:38
【问题描述】:
我想在我的应用程序中使用 BackgroundWorker。我了解到,当我想这样做时:
buttonStart.Enabled = false;
在主线程中,在另一个线程中我应该这样做:
if (buttonStart.InvokeRequired) { buttonStart.Invoke(new Action(() => buttonStart.Enabled = false)); }
else buttonStart.Enabled = false;
但是当它进行比较操作时:
if(tabControlDbSwitch.SelectedIndex == 0)
它不起作用。 所以,这是我的问题:
if ((!tabControlDbSwitch.InvokeRequired && tabControlDbSwitch.SelectedIndex == 0) ||
(tabControlDbSwitch.InvokeRequired && /*What should I write here?*/))
也许你对我有一些提示,因为我在多线程方面完全是新手,但我想尽快学习它。
即我听说有时使用 BeginInvoke 比使用 Invoke 更好,但我不知道为什么以及何时。
【问题讨论】:
标签: c# multithreading comparison-operators