I am new to XAML and Silverlight but I'm a bit confused why I'm seeing now what I'm seeing.
I've made a WCF Data Service, using Entity Data Model tied up to a SQL database. So far so good,
I can Discover the service and use the Entity as an object within my Silverlight application.
I have 2 questions, below is my code, based off Telerik examples.
#region
LoadData2 method
private void LoadData2()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork +=
new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
}
#endregion
#region
worker_DoWork method
void worker_DoWork(object sender, DoWorkEventArgs e)
{
System.Windows.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Uri uri = new Uri(String.Format("{0}/SearchPerson?lastName='{1}'",
svc.BaseUri, lastName),
UriKind.RelativeOrAbsolute);
svc.BeginExecute<
Employee_GetFirstName_Result>(uri, SearchPerson_Completed, null);
});
}
#endregion
#region
SearchPerson_Completed method
private void SearchPerson_Completed(IAsyncResult result)
{
data = svc.EndExecute<
Employee_GetFirstName_Result>(result).ToList();
this.RadGridView1.ItemsSource = data;
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += OnTimerTick;
timer.Interval =
TimeSpan.FromSeconds(1);
timer.Start();
}
#endregion
#region
worker_RunWorkerCompleted event
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//this.RadGridView1.ItemsSource = data;
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += OnTimerTick;
timer.Interval =
TimeSpan.FromSeconds(1);
timer.Start();
}
#endregion
First off, worker_RunWorkerCompleted fires off before SearchPerson_Completed has completed. And I'm sure thats just a newb question but I'm guessing it has something to do with it being aSync but don't know how to resolve it.
And secondly, I can browse the Uri in my browser (of my Stored Procedure) and see the data as expected but when I try to consume it in code my List comes back with 0 items.
Any help would be greatly appreciated.
Thanks!