title: I will load data via API into my ListView async
body: <p>I will load data via API into my ListView async.</p>
  
  <p>I have a list of items (1 to 6300) and in my search box I can search for the items and then it will be displayed in the ListView.</p>
  
  <p>Now I want to show the items Avg prices, which come from a JSON Api.</p>
  
  <p>If you want to take a look at the tool, here is the git link: <a href="https://github.com/Triky313/AlbionOnline-StatisticsAnalysis" rel="nofollow noreferrer">https://github.com/Triky313/AlbionOnline-StatisticsAnalysis</a></p>
  
  <p>My current method looks like this. Once new data is loaded from the API and then again only if they are older than one hour.</p>
  
  <pre><code>    public static ObservableCollection&lt;MarketStatChartItem&gt; MarketStatChartItemList = new ObservableCollection&lt;MarketStatChartItem&gt;();
  
      public static async Task&lt;string&gt; GetMarketStatAvgPriceAsync(string uniqueName, Location location)
      {
          try
          {
              using (var wc = new WebClient())
              {
                  var apiString = "https://www.albion-online-data.com/api/v1/stats/charts/" +
                                  $"{FormattingUniqueNameForApi(uniqueName)}?date={DateTime.Now:MM-dd-yyyy}";
  
                  var itemCheck = MarketStatChartItemList?.FirstOrDefault(i =&gt; i.UniqueName == uniqueName);
  
                  if (itemCheck == null)
                  {
                      var itemString = await wc.DownloadStringTaskAsync(apiString);
                      var values = JsonConvert.DeserializeObject&lt;List&lt;MarketStatChartResponse&gt;&gt;(itemString);
  
                      var newItem = new MarketStatChartItem()
                      {
                          UniqueName = uniqueName,
                          MarketStatChartResponse = values,
                          LastUpdate = DateTime.Now
                      };
  
                      MarketStatChartItemList?.Add(newItem);
  
                      var data = newItem.MarketStatChartResponse
                          .FirstOrDefault(itm =&gt; itm.Location == Locations.GetName(location))?.Data;
                      var findIndex = data?.TimeStamps?.FindIndex(t =&gt; t == data.TimeStamps.Max());
  
                      if (findIndex != null)
                          return data.PricesAvg[(int) findIndex].ToString("N", LanguageController.DefaultCultureInfo);
                      return "-";
                  }
  
                  if (itemCheck.LastUpdate &lt;= DateTime.Now.AddHours(-1))
                  {
                      var itemString = await wc.DownloadStringTaskAsync(apiString);
                      var values = JsonConvert.DeserializeObject&lt;List&lt;MarketStatChartResponse&gt;&gt;(itemString);
  
                      itemCheck.LastUpdate = DateTime.Now;
                      itemCheck.MarketStatChartResponse = values;
                  }
  
                  var itemCheckData = itemCheck.MarketStatChartResponse
                      .FirstOrDefault(itm =&gt; itm.Location == Locations.GetName(location))?.Data;
                  var itemCheckFindIndex =
                      itemCheckData?.TimeStamps?.FindIndex(t =&gt; t == itemCheckData.TimeStamps.Max());
  
                  if (itemCheckFindIndex != null)
                      return itemCheckData.PricesAvg[(int) itemCheckFindIndex]
                          .ToString("N", LanguageController.DefaultCultureInfo);
                  return "-";
              }
          }
          catch (Exception ex)
          {
              Debug.Print(ex.StackTrace);
              Debug.Print(ex.Message);
              return "-";
          }
      }
  </code></pre>
  
  <p>Through the API requests everything loads very long and I can not normally use the search.</p>
  
  <p>Does anyone know of a better solution for loading asnyc data without the search problems?</p>
  
  <p>EDIT:
  Here again visually represented...
  <a href="https://i.stack.imgur.com/5mqlv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5mqlv.png" alt="enter image description here"></a></p>
  
  <p>The item list is already loaded and the search is very fast.</p>
  
  <p>Now you can see some minuses on the right side, there should be numbers. These numbers are loaded later when the item is shown in the list.</p>
  
  <p>The problem: The search is extremely stale if he has 50+ items in the search and then fill them with the data of the API.</p>
  
  <p>For each item, an API request is made.</p>
  
  <p>Can this API query be canceled if the search changes or is there another possibility?</p>