/// <summary> /// Start a search thread /// </summary> public void SearchPoiAction() { CurrentList = DataList; // Stop previous fetching if Processing=true if (Processing) { Processing = false; return; } if (!Append) { DataList.Clear(); } if (fetchThread != null && !fetchThread.IsAlive) { fetchThread.Abort(); } fetchThread = new Thread(e => { this.Processing = true; try { if (!String.IsNullOrEmpty(Keyword)) { SearchPoi(Keyword, City, int.Parse(Offset)); } } catch (Exception ex) { App.Current.Dispatcher.Invoke((Action) delegate { DialogWindow.ShowMessage(null, "We encountered an error when fetching data:\n" + ex.Message, "Sorry"); }); } finally { this.Processing = false; } }); fetchThread.Start(); // Internal POI fetching method void SearchPoi(string keyword, string city, int recordPerPage = 50, int maxRecords = -1) { int totalRecord = 0; List <POI> resultList = SearchPOIRequest(keyword, city, recordPerPage, 1, out totalRecord); MaxProgressValue = (int)Math.Ceiling((float)totalRecord / (float)recordPerPage); CurrentProgressValue = 1; Thread.Sleep(int.Parse(Interval)); if (resultList.Count >= 0) { if (totalRecord > recordPerPage) { for (int i = 2; i <= MaxProgressValue && Processing; i++) { List <POI> pendingList = SearchPOIRequest(keyword, city, recordPerPage, i, out totalRecord); resultList.AddRange(pendingList); CurrentProgressValue++; Thread.Sleep(int.Parse(Interval)); } } } resultList.ForEach((Action <POI>)(poi => { // Update displaylist in main thread App.Current.Dispatcher.Invoke((Action) delegate { this.DataList.Add(poi); }); })); // Update displaylist in main thread App.Current.Dispatcher.Invoke((Action) delegate { this.Processing = true; //MaxPage = (int)Math.Ceiling((float)DataList.Count / (float)int.Parse(offset)); RecordPerPage = recordPerPage; CurrentPage = 1; //RefreshDataPage(); }); } }