Public · Protected · Private
Freezable
Type: Public  |  Created: 2012-08-30  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • Typically in an observer pattern where publisher has to notify changes to all subscrbers(burden). If you freeze -- it need not notify.
    Imagine a SolidBrush has been used to in lot of buttons, and whenever you change the brush color, all the buttons need to be rerendered. Now if we freeze it, we cannot modify Brush colors any more

    Button myButton = new Button();
    Button myButton2 = new Button();
    Button myButton3 = new Button();
    SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);

    if (myBrush.CanFreeze)
    {
        // frozen.
        myBrush.Freeze();
    }

    myButton.Background = myBrush;
    myButton2.Background = myBrush;
    myButton3.Background = myBrush;

    try
    {
        // now you cant modify
        myBrush.Color = Colors.Red;
    }
    catch (InvalidOperationException ex)
    {
        MessageBox.Show("Invalid operation: " + ex.ToString());
    }

    Typically when such object has to hold lot of unmanaged resources (as being a Publisher too)
    it gets more important to be frozen and have a flag for same.
          Brush, Transform, and Geometry classesv

    2012-08-30 18:56
This blog is frozen. No new comments or edits allowed.