Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.37 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How is this not causing a cross thread exception in silverlight?
  2. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  3. {
  4.     QueryTask queryTask = new QueryTask(URL);
  5.     queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryTask_ExecuteCompleted);
  6.     queryTask.Failed += new EventHandler<TaskFailedEventArgs>(queryTask_Failed);
  7.     Query query = new Query();
  8.     query.Where = "Field <> 'XXX'";
  9.     query.OutFields.Add("*");
  10.     queryTask.ExecuteAsync(query);
  11.     BuildingsOrganizationList.ItemsSource = organizationList;
  12. }
  13.  
  14.  
  15. void queryTask_ExecuteCompleted(object sender, QueryEventArgs e)
  16. {
  17.     FeatureSet featureSet = e.FeatureSet;
  18.     foreach (KeyValuePair<string, string> columns in featureSet.FieldAliases)
  19.     {
  20.         TypeGrid.Columns.Add(new DataGridTextColumn()
  21.         {
  22.             Header = columns.Key,
  23.             Binding = new System.Windows.Data.Binding("Attributes[" + columns.Key + "]"),
  24.             CanUserSort = true
  25.         });
  26.     }
  27.     TypeGrid.ItemsSource = featureSet.Features;
  28.     TypeBusyIndicator.IsBusy = false;
  29.  
  30.     testing();
  31. }
  32.  
  33. private void testing()
  34. {
  35.     List<string> temp = new List<string>();
  36.     temp.Add("Item 1");
  37.     temp.Add("Item 2");
  38.     temp.Add("Item 3");
  39.  
  40.     foreach (string org in temp)
  41.     {
  42.         organizationList.Add(org);
  43.     }
  44. }
  45.        
  46. Task.Factory.StartNew(() =>
  47. {
  48.     //code of queryTask_ExecuteCompleted here
  49. });