可能重複:
Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
WPF access GUI from other thread線程和事件
美好的一天, 我寫的類
public class Metric1
{
public event MetricUnitEventHandler OnUnitRead;
public void ReiseEventOnUnitRead(string MetricUnitKey)
{
if (OnUnitRead!=null)
OnUnitRead(this,new MetricUnitEventArgs(MetricUnitKey));
}
.....
}
Metric1 m1 = new Metric1();
m1.OnUnitRead += new MetricUnitEventHandler(m1_OnUnitRead);
void m1_OnUnitRead(object sender, MetricUnitEventArgs e)
{
MetricUnits.Add(((Metric1)sender));
lstMetricUnit.ItemsSource = null;
lstMetricUnit.ItemsSource = MetricUnits;
}
然後,我開始新的線程,每分鐘話費m1的ReiseEven tOnUnitRead方法。
在第lstMetricUnit.ItemsSource = null
行;拋出excepition - 「調用線程無法訪問此對象,因爲不同的線程擁有它。」爲什麼?
這已被問及多次回答。這裏是[列表](http://stackoverflow.com/search?q=wpf+%22other+thread%22) –