async Task findLocationAsync() { String location = findLocationComboBox.Text; LocationRect usermapView = map.BoundingRectangle; Task <List <LocationResult> > t = Task.Factory.StartNew <List <LocationResult> >(() => { return(BingMapsService.findLocations(location, BingMapsKey.SessionKey, usermapView)); }); try { findLocationButton.IsEnabled = false; findLocationComboBox.IsEnabled = false; await t; if (t.Result.Count > 0) { findLocationComboBox.ItemsSource = t.Result; findLocationComboBox.SelectedIndex = 0; } else { findLocationComboBox.ItemsSource = null; } } catch (Exception e) { MessageBox.Show("Error searching location\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { findLocationButton.IsEnabled = true; findLocationComboBox.IsEnabled = true; } }
async void Pin_ToolTipOpening(object sender, ToolTipEventArgs e) { if (IsToolTipLocationSet) { return; } Pin.ToolTip = "Finding Location..."; Location location = new Location(Coordinate.LatDecimal.Value, Coordinate.LonDecimal.Value); Task <LocationResult> t = Task.Factory.StartNew <LocationResult>(() => { return(BingMapsService.findLocation(location, BingMapsKey.SessionKey)); }); try { await t; if (t.Result != null) { Pin.ToolTip = t.Result.Name; IsToolTipLocationSet = true; } else { Pin.ToolTip = "Unknown location"; IsToolTipLocationSet = false; } } catch (Exception ex) { Pin.ToolTip = "Error: " + ex.Message; IsToolTipLocationSet = false; } }