Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Dispatcher.BeginInvoke error in App.xaml file
9 replies. Latest Post by mbaocha on May 19, 2009.
(0)
parimaln
Member
120 points
100 Posts
06-10-2008 8:00 PM |
Hi,
I wish to read xml files available in my Silverlight Web hosting project in the App.xaml file and then call the Page.xaml file once reading is done using web client. But i am getting error "Invalid cross-thread access". This approach was working fine in Beta 1. I have to read all the xml files before page SL pages are displayed. My code in App.xaml.cs file:
{
thread.Start();
InitializeComponent();
}
//BELOW LINE GIVES ME AN ERROR: Invalid cross thread access
DoSomething();
);
.......
regards,
Parimal
Tomek Km...
356 points
69 Posts
06-10-2008 8:24 PM |
Hey,
The exception is thrown from RootVisual getter (the RootVisual property also cannot be accessed from non-UI thread). The solution is to store the dispatcher somewhere before the second thread is started:
Regards,Tomek
06-10-2008 8:53 PM |
Thanks for the response.
In which namespace i can get the Dispatcher object as it is not resolving the App.xaml.cs file?
06-10-2008 8:59 PM |
It's in System.Windows.Threading. Useful tip - when you type class name, press Ctrl + . (dot), and Visual Studio will display menu allows to add approriate using automatically.
06-10-2008 9:10 PM |
Thanks for the response once again.
06-10-2008 9:38 PM |
I think that the simplest solution in your case is to call the web method from the UI thread, especially that you are using async method anyway (HttpWebRequest.BeginGetResponse(...)). Have you considered creating the page in the CommonDataResponseCallBack?
paul_houle
45 points
57 Posts
06-27-2008 9:54 AM |
SL2B2 runs comm callbacks in threads that are drawn from a thread pool -- it doesn't make any difference what thread you begin the request from. The following article talks about effective patterns for using the Dispatcher object:
http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/
vplusplus
10 points
12 Posts
01-26-2009 8:22 PM |
Try System.Windows.Deployment.Current.Dispatcher.BeginInvoke(...)
sunrunne...
5 points
8 Posts
02-12-2009 12:40 PM |
Thanks a ton vplusplus!
mbaocha
14 points
7 Posts
05-19-2009 10:38 AM |
These appears to be a permission issue. What version of IIS are you using?
__________________________ Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}
Cheap Affordable Web Hosting | Web Hosting Nigeria | Best Web Design Company