public static void UpdateAddress(int posid) { try { System.Threading.Thread.Sleep(5000); // Sleep to not get banned by Nominatim using (MySqlConnection con = new MySqlConnection(DBConnectionstring)) { con.Open(); MySqlCommand cmd = new MySqlCommand("select lat, lng from pos where id = @id", con); cmd.Parameters.AddWithValue("@id", posid); MySqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { double lat = Convert.ToDouble(dr[0]); double lng = Convert.ToDouble(dr[1]); dr.Close(); WebHelper.ReverseGecocodingAsync(lat, lng).ContinueWith(task => { try { using (MySqlConnection con2 = new MySqlConnection(DBConnectionstring)) { con2.Open(); MySqlCommand cmd2 = new MySqlCommand("update pos set address = @adress where id = @id", con2); cmd2.Parameters.AddWithValue("@id", posid); cmd2.Parameters.AddWithValue("@adress", task.Result); cmd2.ExecuteNonQuery(); GeocodeCache.Instance.Write(); } } catch (Exception ex) { Logfile.Log(ex.ToString()); } }); } } } catch (Exception ex) { Logfile.Log(ex.ToString()); } }