private void AddPlaces(string keyword) { if (keyword == null) { keyword = ""; } Task <PlacesNearbySearchResponse> task = wBll.GetWorkoutPlaces(keyword, coord); PlacesNearbySearchResponse response = task.Result; List <NearByResult> points = Enumerable.ToList(response.Results); AddMarkers(overlayOne, points); }
private async void LoadTableContentAsync(List <WorkoutCategoryDetailDTO> wcList, List <ActivityLevelDetailDTO> alList) { this.Parent.Parent.Parent.Parent.Enabled = false; List <Task> tasks = new List <Task>(); Dictionary <String, List <string> > keywords = new Dictionary <String, List <string> >(); foreach (var item in wBll.GetWorkoutByWCAL(-1, -1)) { string kw = wBll.ToPlacesKeyword(item.Name); if (kw == null) { kw = ""; } if (keywords.ContainsKey(kw)) { keywords[kw].Add(item.Name); } else { keywords.Add(kw, new List <string> { item.Name }); Task <PlacesNearbySearchResponse> task = wBll.GetWorkoutPlaces(kw, coord); tasks.Add(task); } } while (tasks.Count > 0) { Task finishedTask = await Task.WhenAny(tasks); int index = tasks.IndexOf(finishedTask); List <String> places = keywords.ElementAt(index).Value; Task <PlacesNearbySearchResponse> task = finishedTask as Task <PlacesNearbySearchResponse>; PlacesNearbySearchResponse response = task.Result; if (response.Results.Count() > 0) { for (int k = 0; k < places.Count; k++) { Workout w = wBll.GetWorkout(places[k]); Label lbl = new Label(); lbl.Text = places[k]; lbl.Font = new Font(lbl.Font.Name, 12f); lbl.Height = (int)(lbl.Font.Size * 2.5); lbl.Margin = new Padding(2); lbl.Paint += FrmAddWorkoutPreferences.LblWorkout_Paint; lbl.Click += lblWorkout_Click; int yIndex = wcList.IndexOf(wcList.SingleOrDefault(wc => wc.ID == w.WorkoutCategoryID)); int xIndex = alList.IndexOf(alList.SingleOrDefault(al => al.ID == w.ActivityLevelID)); panelList[yIndex][xIndex].Controls.Add(lbl); } } keywords.Remove(keywords.ElementAt(index).Key); tasks.Remove(finishedTask); } MessageBox.Show("load success"); this.Parent.Parent.Parent.Parent.Enabled = true; }