private Task Check_Currencies_CMC() { return(Task.Run(async() => { if (string.IsNullOrEmpty(CMCAPIKEY)) { return; } var failCounter = 0; while (failCounter < 10) { _ = AwaitOnline(Services.CMC); var ctr = 0; try { Currencies_CMC_Fiat.Clear(); Currencies_CMC_Crypto.Clear(); using (WebClient client = new()) { client.Headers.Add("X-CMC_PRO_API_KEY", CMCAPIKEY); client.Headers.Add("Accepts", "application/json"); { var json = client.DownloadString("https://pro-api.coinmarketcap.com/v1/fiat/map"); var currencies = JsonConvert.DeserializeObject <JSON_CMC_Currencies>(json); foreach (var fiat in currencies.data) { if (!Currencies_CMC_Fiat.Contains(fiat.symbol)) { ctr++; Currencies_CMC_Fiat.Add(fiat.symbol); } } } Currencies_CMC_Fiat = Currencies_CMC_Fiat.OrderBy(x => x).ToList(); } using (WebClient client = new()) { client.Headers.Add("X-CMC_PRO_API_KEY", CMCAPIKEY); client.Headers.Add("Accepts", "application/json"); { var json = client.DownloadString("https://pro-api.coinmarketcap.com/v1/cryptocurrency/map"); var currencies = JsonConvert.DeserializeObject <JSON_CMC_Currencies>(json); foreach (var crypto in currencies.data) { if (!Currencies_CMC_Crypto.Contains(crypto.symbol)) { ctr++; Currencies_CMC_Crypto.Add(crypto.symbol); } } } Currencies_CMC_Crypto = Currencies_CMC_Crypto.OrderBy(x => x).ToList(); } log.Information($"Found {ctr} Currencies at CMC."); Dispatcher.Invoke(() => { ComboBox_ReferenceCurrency.ItemsSource = Currencies_CMC_Fiat.Intersect(Currencies_Fixer); if (REFERENCECURRENCY != null) { var idx = Currencies_CMC_Fiat.IndexOf(REFERENCECURRENCY); if (idx != -1) { ComboBox_ReferenceCurrency.SelectedIndex = idx; } } }); break; } catch (Exception ex) when(ex.Message.Contains("401")) { log.Error("Querying CMC currencies: Unauthorized."); break; } catch (Exception ex) { failCounter++; log.Error($"Querying CMC currencies: {ex.Short()}"); await Task.Delay(5000 * failCounter); } } })); }