假設我有一個控件和字符串的字典。如果我運行後臺工作器,使用控件引用訪問與控件相對應的字符串是否線程安全?在後臺工作線程安全中使用對控件的引用嗎?
Dictionary<Control, string> _ctlDict;
//Called in the main thread
public void Persist()
{
foreach (var control in Controls)
{
_ctlDict.Add(control, control.Name);
}
}
//Called in the background worker
public string GetControlName(Control ctl)
{
return _ctlDict[ctl];
}
這應該是好的,因爲我沒有使用任何控件的屬性 - 我只是使用控件的引用,對吧?
我這麼認爲,謝謝你的回答! –