/// <summary> /// Asynchronously resolves an address to its latitudinal and longitudinal coordinates. May spuriously return no results. /// </summary> /// <param name="address">The address to resolve.</param> /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns></returns> internal async Task <Location> ResolveAddressAsync(string address, CancellationToken token) { if (address == null) { return(new Location()); } Location longLat; if (RequestParser.IsLongLat(address, out longLat)) { return(longLat); } var label = RequestParser.GetLocationLabel(ref address); List <Location> result = new List <Location>(); var client = GetVersionClient(); for (int i = 0; i < 10; i++) { result = await client.ResolveAddressInternalAsync(address, token, i == 9).ConfigureAwait(false); if (result.Any()) { break; } #if !DEBUG await token.WaitHandle.WaitOneAsync(1000, token).ConfigureAwait(false); #endif } if (result.Count == 0) { throw new PrtgRequestException($"Could not resolve '{address}' to an actual address."); } var location = result.First(); if (!string.IsNullOrWhiteSpace(label)) { location.Label = label; } return(location); }