views:

175

answers:

1

I'm having some problems using a backgroundworker in a WPF app. Here's the situation:

I'm trying to do two things. First scanning a number of images and then use barcode recognition on the scanned images. I'm retrieving the scanned images as a list of BitmapSource objects and these should be available to my backgroundworker thread.

After some googling it seems most solutions are specific to communication with ui elements on the main thread because none of the solutions I've found have worked for me. I've tried using delegates and the dispatcher but to no avail.

I need the BitmapSources to create Bitmaps with them which is the input of the barcode recognition.

Thanks,

Kevin

A: 

In WPF, all DispatcherObjects (not only UI elements) can be accessed only from the thread that created them. BitmapSource inherits (indirectly) from DispatcherObject, so it follows this rule. However, it also inherits from Freezable, and Freezable objects can be accessed from another thread if they are frozen.

So, after your BitmapSource is initialized, you can call Freeze on it, and it will be accessible from other threads.

Thomas Levesque
Problem solved, thanks!
kwe