I am working on a C # WPF application that loads a lot of images and displays it as thumbnails. I would like to do this in a multithreaded way. So I tried to implement BackgroundWorker.
BackgroundWorker DoWork () code:
string[] files = e.Argument as string[]; foreach (string file in files) { ImageModel image = new ImageModel(); image.FilePath = file; _importWorker.ReportProgress(1, image); _imageCollectionVM.Images.Add(image);
In my XAML code, I bind to the BitmapImage ImageModel property. (AsyncState = True does not help.) Here I get this error: "DependencySource" and "DependencyObject" must be in the same thread.
<Image Source="{Binding BitmapImage}" />
If I comment on this, the image seems to be imported, but I cannot access it, for example. selecting it in a ListView. In his SelectionChanged, he says then that this object has a different thread.
How to solve these problems? Thanks in advance!
source share