I've enocountered a problem while trying to use Emgu to capture images from a webcam. To do this task, Emgu uses unmanaged opencv libraries. So the problem is that I can't update my GUI (WPF Image control) from System.Timers.Timer Elapsed event. I know it's running in different thread, but hey, that's why I'm using a Dispatcher. It's the first time I can't do it with Dispatcher. Getting InvalidOperationException with "The calling thread cannot access this object because a different thread owns it.". I've spent the whole day searching for a solution, but still couldn't fix it. Any ideas why does it happen?
webcam.OnNewFrame += newBitmapSource => this.imgCaptured.Dispatcher.Invoke
(
new Action(delegate
{
this.imgCaptured.Source = newBitmapSource;
}),
DispatcherPriority.Background
);
The last thing on Stack Trace is: System.Windows.Threading.Dispatcher.VerifyAccess()
However, if I call Dispatcher.CheckAccess() it returns true.
UPDATE:
Finally I found it out by myself: the BitmapSource had to be created on UI Thread. It seems like it can't use this object otherwise.