tags:

views:

26

answers:

2

Hi everyone! I have a SL application that reads some data from the database, which I do through a WCF Service. I was having some delay problems due to this access, so I solved it by loading all the data into a dictionary in my app. Now I want to make sure the application will only be displayed after I loaded all this information, how can I do that? I thought that just puting my InitializeComponents after the data load would be enough, but it is not. Here is some piece of my code:

 public Brasil()
 {
     //InitializeComponent();
     webService = new DataRetrieverReference.DataRetrieverClient();
     webService.GetCounterCompleted += new EventHandler<WebPortos.DataRetrieverReference.GetCounterCompletedEventArgs>(webService_GetCounterCompleted);
     webService.GetCounterAsync();
     webService.GetDataCompleted += new EventHandler<DataRetrieverReference.GetDataCompletedEventArgs>(webService_GetDataCompleted);

 }

 void webService_GetCounterCompleted(object sender, WebPortos.DataRetrieverReference.GetCounterCompletedEventArgs e)
 {
     int counter = e.Result;
     this.dictionary = new Dictionary<int, WebPortos.DataRetrieverReference.vwPortos_SEP>();

     for (int i = 0; i < counter; i++)
     {
         webService.GetDataAsync(i);
     }

     InitializeComponent();
 }

As you can see, I put it inside my data loading method, but it didn't work. Any tips?

+1  A: 

It is bad practice to delay the creation of views in any way. Leave InitializeComponent in the constructor! :)

What you want to do is simply hide your display until the data is ready. Easiest way (to keep this example simple) is start with Visibility set to collapsed on some parent element on the page, then set that to Visible again after the data is loaded.

Real world solutions involve using busy indicators to stop interaction with specific areas/controls while the data loads.

Enough already
The problem is that it is intended to be real world solution ... I'll fix it after the deadline.
Bruno
So why not use a busyindicator? Just place all content into one and set the IsBusy property to control it. Cheer
Enough already
A: 

Looking at your code the GetDataAsync is making an async request for each set of data and then performing the InitializeComponent afterwards. So you would need to delay the InitializeComponent call until after all the GetDataCompleted callbacks have been fired and so all the data retrieved.

Phil Wright