public void LoadData() { mapFunctionsClass = new MapFunctionsClass(gMapControl1); //instantiate the MapFunctionsClass helper class toolStripStatusLabel1.Text = "Downloading latest phone log..."; NetworkClass.DownloadFile(settings.FileURL, this); //ask to download the phone log file. upon success, the FileDownloaded() callback method will be called }
public void FileDownloaded(string contents) { toolStripStatusLabel1.Text = "Ready"; //process the string contents into a list of DataRows List <DataRow> table = HelperFunctionsClass.getTableFromText(contents, toolStripTextBoxDataNumbersToLoad.Text); if (table.Count > 0) { //process the list of DataRows into a list of ListViewItems List <ListViewItem> listViewItems = HelperFunctionsClass.getListViewItemsFromTable(table); //add the ListViewItems to the listview control listView1.Items.Clear(); //clear pre-existing items from the listview table listView1.Items.AddRange(listViewItems.ToArray()); //listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); apparently, this command is a CPU hog and makes the app's UI laggy while populating the listview table toolStripStatusLabel2.Text = $"{listView1.Items.Count} records added!"; //center the map at the last position mapFunctionsClass.centerMapAt(Double.Parse(table[table.Count - 1].Latitude), Double.Parse(table[table.Count - 1].Longitude)); //place markers for all positions for (int i = 0; i < table.Count; i++) { DataRow dataRow = table[i]; mapFunctionsClass.putMarkerAt(i, dataRow.DateTime, Double.Parse(dataRow.Latitude), Double.Parse(dataRow.Longitude), GMarkerGoogleType.blue_pushpin); mapFunctionsClass.setTooltipMode(showTooltipToolStripMenuItem.Checked ? MarkerTooltipMode.OnMouseOver : MarkerTooltipMode.Never); } ; //resolve latlong to address and add to the listview Thread thread = new Thread(new ThreadStart(() => { int listViewEntries = 0; this.Invoke(new Action(() => listViewEntries = listView1.Items.Count)); for (int i = 0; i < listView1.Items.Count; i++) { string lat = "", lon = ""; this.Invoke(new Action(() => { lat = listView1.Items[i].SubItems[1].Text; lon = listView1.Items[i].SubItems[2].Text; })); try { string address = NetworkClass.GetAddressHERE(lat, lon, settings.HEREApiKey); this.Invoke(new Action(() => { listView1.Items[i].SubItems[5].Text = address; })); } catch (HttpRequestException webex) { Debug.WriteLine("Cannot load address name from latlong."); } } })); thread.IsBackground = true; thread.Start(); } else { toolStripStatusLabel1.Text = "No entries found in log file"; } }