Geeks With Blogs
David Jacobus SharePoint Consultant

I have been working on a Silverlight Navigation application which uses LINQ to query an XML data source and has been working without a hitch until I added a control  to the landing page. All other pages which worked fine were loaded from the navigation service    Once I added the control I got a page not found error!  (The page is there) and If navigated to, it works as expected.   What happens, it that I closed the error Modal dialog and then clicked on another page, then navigate back to the landing page it works!  However, the page doesn’t load on initialization. 

I thought the issue is with the data access timing.  Because the data access (LINQ query) is asyncronomous it hasn't finished retrieving data before the control on the page is requesting the data.  If I single step through the code I see a The typical object error when trying to access the collection being filled from the data access code.

On my Development Computer, I do not have an issue as I have a dummy data source to query against and the Page loads fine!

So the issue seems to be that I need to put a delay of some sort before the controls are loaded. Basically the entire application loaded some data from an xml file gathered from a SharePoint list.

I found the solution by re-querying the data source and after the data loaded, I added my control to the page controls collection dynamically.

This was my first ever issue with asyncronomous programming and it is a lesson which will be ingrained into my Silverlight development forever as I had a few hours of debugging to help chisel it into my brain housing group!

Posted on Tuesday, January 18, 2011 6:26 PM | Back to top


Comments on this post: Silverlight Asyncronomous Programming

# re: Silverlight Asyncronomous Programming
Requesting Gravatar...
Thanks to you and Google. I couldn't imagine this was the case for me, but it was. Instead of a delay I just removed the control from the .xaml and built and added it to the UI once the data retrieval was done. Ta-daa.

You are right, this async stuff does require some changes in approach.
Left by Andy Hooper on Feb 16, 2012 1:04 AM

Your comment:
 (will show your gravatar)


Copyright © David Jacobus | Powered by: GeeksWithBlogs.net