[Solved] WPF Calling thread cannot access with eventargs


The FinalFrame_NewFrame event is raised on a worker thread by your “video device”…thus as you have figured out you need to use Invoke to get access to your pboLive element on the UI thread…but you need to pass across the “bitmap”.

I believe you just need this:

    this.Dispatcher.Invoke(
        new Action<Bitmap>(
            (bitmap) =>
            {
                pboLive.Source = ImageSourceForBitmap(bitmap);
            }
        ),
        (Bitmap)eventArgs.Frame.Clone()
        );

I think the Clone is unnecessary, if you are creating a BitmapImage in that ImageSourceForBitmap function.

If you are using CreateBitmapSourceFromHBitmap then I can see why you are doing your own copy of the Bitmap (whose lifetime is owned by the Video device)…but you might as well create a BitmapImage or something equivalent.

6

solved WPF Calling thread cannot access with eventargs