我可以在两个线程之间安全地共享这个“状态”对象吗?
private bool status = false;
private void uiNewThread_bootloaderStartIdSetupAuto()
{
while (status)
;
}
上面是将从下面的 UI 启动的新线程:
private void uiBtnBootloaderStartIdSetupAuto_Click(object sender, EventArgs e)
{
if (MessageBox.Show("ID will be setup starting from 1 to 16. \n\nAfter pressing 'YES', press the orange button one-by-one on the nodes.\nThe first pressed node will have number 1, the next number 2, and so on... \n\nWhen done, hit DONE button.", "ID setup", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
status = true;
Thread transmitConfig = new Thread(new ThreadStart(uiNewThread_bootloaderStartIdSetupAuto)); //close port in new thread to avoid
transmitConfig.Start();
}
else
{
Log(LogMsgType.Normal, "User cancelled");
status = false;
}
}