可能重复:
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) –