Question

I want to pass a writeablebitmap object generated from UI (WPF) into an asynchronous call but don't want to update the main thread's writeablebitmap. I just want to read some properties such as pixel height and width. In the new thread I can't access any of the writeablebitmap's properties since it thinks I'm trying to mess with the main thread's writeablebitmap's properties. I receive the exception: "The calling thread cannot access this object because a different thread owns it." Some responses in other threads suggested they use Dispatcher.BeginInvoke, but if I just want a copy of the writeablebitmap object to read data from, is this necessary?

Was it helpful?

Solution

Freezables lose their Thread-affinity when they're freezed. try calling Freeze() in the WritableBitmap.

Otherwise you can create a clone by using Clone() and then freeze the clone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top