private void ReadWebRequestCallback(IAsyncResult callbackResult) { try { String results = HttpUtils.GetResponse(callbackResult); Collection<Dictionary<String, String>> unsortedItems = JsonUtils.GetItems(results, new String[] { "name", "id" }); Collection<Dictionary<String, String>> sortedItems = ModelItem.SortItems(unsortedItems, "name"); Deployment.Current.Dispatcher.BeginInvoke(() => this.Counties.Clear()); foreach (Dictionary<String, String> county in sortedItems) { ModelItem countyItem = new ModelItem(); countyItem.Name = county["name"]; countyItem.Id = county["id"]; Deployment.Current.Dispatcher.BeginInvoke(() => this.Counties.Add(countyItem)); } Deployment.Current.Dispatcher.BeginInvoke(() => SystemTray.ProgressIndicator.IsIndeterminate = false); } catch (Exception ex) { Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(ex.Message)); } }
private void ReadWebRequestCallback(IAsyncResult callbackResult) { try { String results = HttpUtils.GetResponse(callbackResult); var unsortedItems = JsonUtils.GetItems(results, new String[] { "name", "id" }); var sortedItems = ModelItem.SortItems(unsortedItems, "name"); Deployment.Current.Dispatcher.BeginInvoke(() => this.Cinemas.Clear()); foreach (Dictionary<String, String> cinema in sortedItems) { // need to create local variable reference as loop variable cinema will change before UI gets update. ModelItem cinemaItem = new ModelItem(); cinemaItem.Name = cinema["name"]; cinemaItem.Id = cinema["id"]; Deployment.Current.Dispatcher.BeginInvoke(() => this.Cinemas.Add(cinemaItem)); } Deployment.Current.Dispatcher.BeginInvoke(() => SystemTray.ProgressIndicator.IsIndeterminate = false); } catch (Exception ex) { Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(ex.Message)); } }