2012-07-20 27 views
0

我正在Silverlight 3.0中创建一个应用程序。在该应用程序,我有一个公共的方法Silverlight中无效的交叉线程访问

public void DrawWavform() 
{ 
    Line[,] line = new Line[10,200]; 
    line[i,j]= new Line();//i am getting error here of invalid thread access 
    //some operation 

} 

在应用我和每用户输入创建不同的线程和新创建的线程中调用DrawWaveform方法。我想并行操作。请提示我解决方法。提前感谢。

回答

6

更改GUI的任何操作都必须在UI线程上执行。

Deployment.Current.Dispatcher.BeginInvoke(() => 
{ 
    // update ui 
}); 

(SomeDependencyObject).Dispatcher.BeginInvoke(() => { /* ... */ }); 

不管怎么说,这个代码应该很少使用,并且只包含UI相关的代码:这可以通过使用dispatcher来完成。在UI线程上执行昂贵的操作会导致应用程序挂起。

相关问题