コード例 #1
0
        internal static void Add(ISystemColorTracker obj)
        {
            lock (typeof(SystemColorTracker)) {
                Debug.Assert(list != null, "List is null");
                Debug.Assert(list.Length > 0, "INITIAL_SIZE was initialized after list");

                if (list.Length == count)
                {
                    GarbageCollectList();
                }

                if (!addedTracker)
                {
                    addedTracker = true;
                    SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(OnUserPreferenceChanged);
                }

                // Strictly speaking, we should grab a lock on this class.  But since the chances
                // of a problem are so low, the consequences so minimal (something will get accidentally dropped
                // from the list), and the performance of locking so lousy, we'll risk it.
                int index = count;
                count++;

                // COM+ takes forever to Finalize() weak references, so it pays to reuse them.
                if (list[index] == null)
                {
                    list[index] = new WeakReference(obj);
                }
                else
                {
                    Debug.Assert(list[index].Target == null, "Trying to reuse a weak reference that isn't broken yet: list[" + index + "], length =" + list.Length);
                    list[index].Target = obj;
                }
            }
        }
コード例 #2
0
 internal static void Add(ISystemColorTracker obj)
 {
     lock (typeof(SystemColorTracker))
     {
         if (SystemColorTracker.list.Length == SystemColorTracker.count)
         {
             SystemColorTracker.GarbageCollectList();
         }
         if (!SystemColorTracker.addedTracker)
         {
             SystemColorTracker.addedTracker     = true;
             SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemColorTracker.OnUserPreferenceChanged);
         }
         int local_0 = SystemColorTracker.count;
         ++SystemColorTracker.count;
         if (SystemColorTracker.list[local_0] == null)
         {
             SystemColorTracker.list[local_0] = new WeakReference((object)obj);
         }
         else
         {
             SystemColorTracker.list[local_0].Target = (object)obj;
         }
     }
 }
コード例 #3
0
 internal static void Add(ISystemColorTracker obj)
 {
     lock (typeof(SystemColorTracker))
     {
         if (list.Length == SystemColorTracker.count)
         {
             GarbageCollectList();
         }
         if (!addedTracker)
         {
             addedTracker = true;
             SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemColorTracker.OnUserPreferenceChanged);
         }
         int count = SystemColorTracker.count;
         SystemColorTracker.count++;
         if (list[count] == null)
         {
             list[count] = new WeakReference(obj);
         }
         else
         {
             list[count].Target = obj;
         }
     }
 }
コード例 #4
0
ファイル: SystemColorTracker.cs プロジェクト: JianwenSun/cc
     internal static void Add(ISystemColorTracker obj) {
         lock (typeof(SystemColorTracker)) {
             Debug.Assert(list != null, "List is null");
             Debug.Assert(list.Length > 0, "INITIAL_SIZE was initialized after list");
             
             if (list.Length == count) {
                 GarbageCollectList();
             }
             
             if (!addedTracker) {
                 addedTracker = true;
                 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(OnUserPreferenceChanged);
             }
 
             // Strictly speaking, we should grab a lock on this class.  But since the chances
             // of a problem are so low, the consequences so minimal (something will get accidentally dropped
             // from the list), and the performance of locking so lousy, we'll risk it.
             int index = count;
             count++;
 
             // COM+ takes forever to Finalize() weak references, so it pays to reuse them.
             if (list[index] == null)
                 list[index] = new WeakReference(obj);
             else {
                 Debug.Assert(list[index].Target == null, "Trying to reuse a weak reference that isn't broken yet: list[" + index + "], length =" + list.Length);
                 list[index].Target = obj;
             }
         }
     }
 internal static void Add(ISystemColorTracker obj)
 {
     lock (typeof(SystemColorTracker))
     {
         if (list.Length == SystemColorTracker.count)
         {
             GarbageCollectList();
         }
         if (!addedTracker)
         {
             addedTracker = true;
             SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemColorTracker.OnUserPreferenceChanged);
         }
         int count = SystemColorTracker.count;
         SystemColorTracker.count++;
         if (list[count] == null)
         {
             list[count] = new WeakReference(obj);
         }
         else
         {
             list[count].Target = obj;
         }
     }
 }
コード例 #6
0
 private static void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
 {
     if (e.Category == UserPreferenceCategory.Color)
     {
         for (int i = 0; i < count; i++)
         {
             ISystemColorTracker target = (ISystemColorTracker)list[i].Target;
             if (target != null)
             {
                 target.OnSystemColorChanged();
             }
         }
     }
 }
コード例 #7
0
 private static void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
 {
     if (e.Category != UserPreferenceCategory.Color)
     {
         return;
     }
     for (int index = 0; index < SystemColorTracker.count; ++index)
     {
         ISystemColorTracker systemColorTracker = (ISystemColorTracker)SystemColorTracker.list[index].Target;
         if (systemColorTracker != null)
         {
             systemColorTracker.OnSystemColorChanged();
         }
     }
 }
コード例 #8
0
 private static void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
 {
     // Update pens and brushes
     if (e.Category == UserPreferenceCategory.Color)
     {
         for (int i = 0; i < count; i++)
         {
             Debug.Assert(list[i] != null, "null value in active part of list");
             ISystemColorTracker tracker = (ISystemColorTracker)list[i].Target;
             if (tracker != null)
             {
                 // If object still around
                 tracker.OnSystemColorChanged();
             }
         }
     }
 }