Dany
Dany

Reputation: 2174

Invalid cross thread access in silverlight

i am making an application in silverlight 3.0. In that application i have one public method as

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

}

In application i am creating different threads as per user inputs and calling DrawWaveform method from that newly created thread. I want to parallel opeation.Please suggest me solution.Thanks in advance.

Upvotes: 0

Views: 6828

Answers (1)

Gene
Gene

Reputation: 4232

Any operation changing the GUI must be executed on the UI thread. This can be done using the dispatcher:

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

or

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

Anyway, this code should be used very rarely and contain only UI related code. Executing expensive operations on the UI thread will cause your application to hang.

Upvotes: 7

Related Questions