silverlight中的交叉线程访问无效

Dan*_*any 0 silverlight multithreading drawing line visual-studio-2010

我正在使用silverlight 3.0进行申请.在那个应用程序中,我有一个公共方法

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

}
Run Code Online (Sandbox Code Playgroud)

在应用程序中,我根据用户输入创建不同的线程,并从新创建的线程调用DrawWaveform方法.我想并行操作.请建议我解决.谢谢提前.

Gen*_*ene 6

必须在UI线程上执行更改GUI的任何操作.这可以使用调度程序完成:

Deployment.Current.Dispatcher.BeginInvoke( () =>
{
  // update ui
});
Run Code Online (Sandbox Code Playgroud)

要么

(SomeDependencyObject).Dispatcher.BeginInvoke( () => { /* ... */ } );
Run Code Online (Sandbox Code Playgroud)

无论如何,这个代码应该很少使用,只包含与UI相关的代码.在UI线程上执行昂贵的操作将导致应用程序挂起.