Sorry If this question has already been asked, but I cannot find the solution. I was searching for loading images into listview directly from URL using OberveableCollection that doesn't hang my UI somehow, I got this solution, and it's working great, but I also want to show username along with image; how can I modify the below code to do so.
public void LoadImage(object uri)
{
try
{
var decoder = new JpegBitmapDecoder(new Uri(uri.ToString()), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
decoder.Frames[0].Freeze();
this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<ImageSource>(SetImage), decoder.Frames[0]);
}
catch(Exception ex)
{
Debug.WriteLine($"{ex.Message}\n{uri}");
}
}
public void SetImage(ImageSource source)
{
Debug.WriteLine("Inside set image!");
LocalMembers local = new LocalMembers(source);
members.Add(local);
Debug.WriteLine($"Image has been set {members.Count()}");
}
Here I'm using ThreadPool to call the function
ThreadPool.QueueUserWorkItem(LoadImage, img);
right now, it's only taking img URL, but i also want to pass other things like username, memberId my class, LocalMembers has three member
private ImageSource imageURL;
private string username;
private string id;
any idea how can i modify this function to show other data like username and id also using this threadpool