1
votes

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?

1
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. - Federico Berasategui
Freezing it was exactly what I was looking for, thank you very much! - Jack B
please mark my answer as accepted if it was useful you you =) - Federico Berasategui

1 Answers

1
votes

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