title: Loading multiple images from file path and assigning them to image control inside collection view sometimes does not load properly
body: <p>There are around 30-40 images that gets downloaded from the server and saved to local and then file path is passed through which image source is generated. Download call is made whenever user scrolls the collectionview. Sometimes images are getting loaded completely and sometime partially.</p>
  <pre><code>                    &lt;CollectionView 
                              HorizontalOptions=&quot;FillAndExpand&quot;
                              HorizontalScrollBarVisibility=&quot;Never&quot;
                              VerticalScrollBarVisibility=&quot;Never&quot;
                              SelectionMode=&quot;Single&quot;
                              ItemSizingStrategy=&quot;MeasureAllItems&quot;
                              ItemsSource=&quot;{Binding Items}&quot;&gt;
                      &lt;CollectionView.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Image Source=&quot;{Binding Image}&quot;&gt;&lt;/Image&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/CollectionView.ItemTemplate&gt;
                   &lt;/CollectionView&gt;
  </code></pre>
  <p>C#</p>
  <pre><code>   await Utility.FileHanler.Download(Id, resourceTypeId, material, ThumbURL, token, (arg) =&gt;
                              {
                                  
                                  LoadImage(arg);
                              });
  
  
    public async Task Download(int id, int resourceType,string fileName,string thumbnailUrl, CancellationToken token , Action&lt;string&gt; CompletionHandler)
      {
          string destinationFolder;
          
          destinationFolder = Path.Combine(FileHandler.Images, id.ToString());
          
          try
          {
              if (!Directory.Exists(destinationFolder))
              {
                  Directory.CreateDirectory(destinationFolder);
              }
              ServicePointManager.Expect100Continue = true;
              ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
              token.ThrowIfCancellationRequested();
              WebRequest wr = WebRequest.Create(thumbnailUrl + App.Token);
              WebResponse ws = await wr.GetResponseAsync();
              Stream s = ws.GetResponseStream();
              byte[] buffer = new byte[10240];
              var filePath = Path.Combine(destinationFolder, fileName);
              var dlStream = new FileStream(filePath, FileMode.Create);
              int readBytes = s.Read(buffer, 0, 10240);
              while (readBytes &gt; 0)
              {
                  dlStream.Write(buffer, 0, readBytes);
                  readBytes = s.Read(buffer, 0, 10240);
              }
              dlStream.Close();
              dlStream.Dispose();
              s.Close();
              s.Dispose();
              ws.Close();
              CompletionHandler?.Invoke(filePath);
          }
          catch (Exception ex)
          {
              throw ex;
          }
  
      public void LoadImage(string filePath)
      {
            Device.BeginInvokeOnMainThread(() =&gt;
            {
             Image = ImageSource.FromFile(filePath);
            });
      }
         
        
               
  </code></pre>
  <p><a href="https://i.stack.imgur.com/owg8D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/owg8D.png" alt="CLipped Image" /></a></p>
  <p><a href="https://i.stack.imgur.com/TkgbA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TkgbA.png" alt="Image Loaded fully" /></a></p>