Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

double freeze #11074

Unanswered
trebahl asked this question in Q&A
Aug 27, 2025 · 1 comments · 2 replies
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

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.

You must be logged in to vote
2 replies
Comment options

Actually, CanFreeze is not called because it is internal bool Freeze(bool isChecking) that gets called (see PropertyMetaData.DefaultFreezeValueCallback), bypassing the call to CanFreeze.

Comment options

GetAsFrozen won't help in my case because the double freeze is not called by me but by wpf's guts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /