-
Notifications
You must be signed in to change notification settings - Fork 1.2k
-
Freezable.FreezeCore loops over all the values of dependencyproperties stored in the object, and freezes the values that are Freezable. Should it not check if they are already frozen and call freeze only if they are not?
I stumbled upon this while freezing an imagebrush whose imagesource had already been frozen, on another thread. I had understood that a frozen imagesource can be used on different threads so I thought there shouldn't be a problem. But freezing the imagebrush will try to freeze again the imagesource, which immediately throws an execption because we're not on the right thread.
You may say I'm looking for trouble with my multithreading, but even on a single thread, there would be a double freeze which I imagine is not ideal or could even cause issues.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
My reading of the documentation agrees with yours in that a frozen object should be usable across threads. I would expect Freeze()
to count as such usage. It is also strange that CanFreeze
would return true and then Freeze()
throw. With that said GetAsFrozen()
does the check and returns itself if the object is already frozen.
Beta Was this translation helpful? Give feedback.
All reactions
-
Actually, CanFreeze is not called because it is internal bool Freeze(bool isChecking)
that gets called (see PropertyMetaData.DefaultFreezeValueCallback
), bypassing the call to CanFreeze.
Beta Was this translation helpful? Give feedback.
All reactions
-
GetAsFrozen
won't help in my case because the double freeze is not called by me but by wpf's guts.
Beta Was this translation helpful? Give feedback.