title: async method within non-async loop
body: <p>I am using a loop to place images in my canvas, there is a method that needs to check if each looped images have an attribute that is stored in a JSON file.</p>
  
  <p>the checkImage method works fine outside the loop, but when I place it in the loop it gives this error: </p>
  
  <blockquote>
    <p>"Access denied, file is used by another process"</p>
  </blockquote>
  
  <p>Since the method gets called for every image created by the loop I guess that I need to close the JSON file after its serialized or something, but how?</p>
  
  <p>The loop:</p>
  
  <pre><code> while (i &lt; blauw)
                  {
                      checkImage(i); //checks if it has the attribute or not
                      ImageBrush brush = new ImageBrush();
                      Button Btn = new Button();
                      Uri uri = new Uri("ms-appx://Blijfie/images/" + selected + "/" + blauwpics[i]);
                      BitmapImage imgSource = new BitmapImage(uri);
                      brush.ImageSource = imgSource;
                      Btn.Background = brush;
                      Btn.Width = 200;
                      Btn.Height = 200;
  
                      if (i &gt;= 5 &amp;&amp; i &lt; 10)
                      {
                          Canvas.SetTop(Btn, marginTop);
                          Canvas.SetLeft(Btn, marginLeft2);
                          marginLeft2 = marginLeft2 + 250;
                      }
                      else if (i &lt; 6)
                      {
                          Canvas.SetLeft(Btn, marginLeft);
                          marginLeft = marginLeft + 250;
  
                      }
                      else if (i &gt;= 10)
                      {
                          Canvas.SetTop(Btn, marginTop2);
                          Canvas.SetLeft(Btn, marginLeft3);
                          marginLeft3 = marginLeft3 + 250;
                      }
                      main.Children.Add(Btn);
                      i++;
  
                  }
  </code></pre>
  
  <p>CheckImage method:</p>
  
  <pre><code> private async void checkImage(int id) {
                      var foldertest = ApplicationData.Current.TemporaryFolder;
                      var files = await foldertest.GetFilesAsync();
                      var desiredFile = files.FirstOrDefault(x =&gt; x.Name == "Dierendb.json");
                      var textContent = await FileIO.ReadTextAsync(desiredFile);
  
                      var result = JsonConvert.DeserializeObject&lt;List&lt;Dier&gt;&gt;(textContent);
  
                      id++;
  
                      if (result[id].PathDier.Equals(""))
                      {
                          //do this
                      }
                      else
                      {
                          //do that
                      }
  
  
                      string dierenlijst = JsonConvert.SerializeObject(result, Formatting.Indented);
                      await Windows.Storage.FileIO.WriteTextAsync(desiredFile, dierenlijst, Windows.Storage.Streams.UnicodeEncoding.Utf8);
  
      }
  </code></pre>