© 2026 Hedgehog Software, LLC
img.Source = image;
Task.Run(...)
img.Dispatcher.Invoke(() => img.Source = image);
Dispatcher.BeginInvoke(() => { img.Source = image; });
System.InvalidOperationException: "The calling thread cannot access this object because a different thread owns it."
BitmapImage[] BitmapImages = await Task.Run(() => { BitmapImage[] bitmapImages = new BitmapImage[files.Count]; int i = 0; foreach (string file in files) { BitmapImage image = new(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.DecodePixelWidth = 200; image.UriSource = new Uri(file); image.EndInit(); bitmapImages[i++] = image; } return bitmapImages; }); foreach (BitmapImage image in images) { if (image == null) return; Image img = new(); img.Source = image; } return ;