public void RefreshList() { BackgroundWorker w = new BackgroundWorker(); IsLoading = true; w.DoWork += (obj, args) => args.Result = AmazonClient.GetInstances(); w.RunWorkerCompleted += (obj, args) => { IsLoading = false; if (args.Error != null) { _updateTimer.IsEnabled = false; throw new Exception("Error downloading server list: " + args.Error.Message, args.Error); } var newInstances = args.Result as List <Instance>; var previousSelection = listBox.SelectedItem as Instance; using (InstanceCollectionView.DeferRefresh()) AmazonClient.MergeInstanceList(Instances, newInstances); if (listBox.Items.Count > 0) { if (previousSelection != null && listBox.Items.Contains(previousSelection)) { listBox.SelectedItem = previousSelection; } else { listBox.SelectedIndex = 0; } } }; w.RunWorkerAsync(); }
private void OK_Click(object sender, RoutedEventArgs e) { try { Cursor = Cursors.Wait; if (!App.CheckConfig()) { return; } if (!AmazonClient.CheckConnection()) { return; } DialogResult = true; } finally { Cursor = Cursors.Arrow; } }