I'm working on a project where we need to capture and process images in order to control a robot. Those two things are working just fine.
What I can't seem to be able to figure out is how to use WPF to display the pre- and post-processing images.
I have an app that is using this code:
public CamNotification(string label1, string label2, BitmapSource image1, BitmapSource image2)
private bool hwLink_SetInfos(CamNotification info)
{
try
{
Application.Current.Dispatcher.BeginInvoke((Action)(() =>
{
lblText1.Content = info.Label1;
lblText2.Content = info.Label2;
ImageBox1.Source = info.Image1;
ImageBox2.Source = info.Image2;
InvalidateVisual();
}));
return true;
}
catch (Exception ex)
{
Debugger.Break();
return false;
}
}
It changes both the labels describing the images and the 'image.source's themselves.
It works ->fine<- when I use a WPF-button to call the code, but when I try it using a WorkerThread from a Threadpool that replaces the two 'image.source's the images are not displayed, even though the labels are.
Moreover, if I have already pressed the button and the pictures were displayed, a call from the ->WorkerThread<- that ends up in the MainThread removes the images and leaves a blank area instead of updating them to the new content.
Using the Dispatcher I have already removed all crossthead-issues, Labels are updated but the "PresentationFramework -> System.Windows.Controls.Image" is cleard and not updated :-(
While looking through stackoverflow I found this question:
It seems to be concerned with a problem similar to mine. However, neither the answers nor the OPs comment about how he solved his problem have helped me.
I would appreciate any help you could give me.