Jan Kučera

Hello, I have a couple of ImageSource (dependency) properties, and during the OnRender method, I juste use:

drawingContext.DrawRectangle(new ImageBrush(Source1), null, new Rect(0, 0, Source1.Width, Source1.Height));

drawingContext.DrawRectangle(new ImageBrush(Source2), ...);

drawingContext.DrawRectangle(new ImageBrush(Source3), ...);

drawingContext.DrawRectangle(new ImageBrush(Source4), ...);

..and it works. However, I have seen some example, where the ImageBrush is frozen before using.

Why Should I froze it as well Any performance issues with above code (and curious one - who disposes these ImageBrushes )



Re: Windows Presentation Foundation (WPF) Why should I freeze?

lee d

if you have an object and do not intend to modify you can gain performance if you Freeze it. once frozen it can be shared across threads




Re: Windows Presentation Foundation (WPF) Why should I freeze?

Jan Ku?era

But that is useless when I create it again on each paint, isn't it

That would make sense if keep reference to all the brushes inbetween rendering calls.





Re: Windows Presentation Foundation (WPF) Why should I freeze?

lee d

if the source of the brush is changing then no use




Re: Windows Presentation Foundation (WPF) Why should I freeze?

Jan Ku?era

Okay, so when/how do they get disposed