Beispiel #1
0
 private static void OnShutdown(object sender, EventArgs e)
 {
     if (handleCount > 0)
     {
         lock (internalSyncObject)
         {
             for (int i = 0; i < hashBuckets.Length; i++)
             {
                 HandleBucket wrapper = hashBuckets[i];
                 if ((wrapper.handle != IntPtr.Zero) && (wrapper.handle != new IntPtr(-1)))
                 {
                     HandleRef hWnd = new HandleRef(wrapper, wrapper.handle);
                     System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(hWnd, -4, new HandleRef(null, userDefWindowProc));
                     System.Windows.Forms.UnsafeNativeMethods.SetClassLong(hWnd, -24, userDefWindowProc);
                     System.Windows.Forms.UnsafeNativeMethods.PostMessage(hWnd, 0x10, 0, 0);
                     if (wrapper.window.IsAllocated)
                     {
                         NativeWindow target = (NativeWindow)wrapper.window.Target;
                         if (target != null)
                         {
                             target.handle = IntPtr.Zero;
                         }
                     }
                     wrapper.window.Free();
                 }
                 hashBuckets[i].handle    = IntPtr.Zero;
                 hashBuckets[i].hash_coll = 0;
             }
             handleCount = 0;
         }
     }
     WindowClass.DisposeCache();
 }
Beispiel #2
0
 private static void RemoveWindowFromTable(IntPtr handle, NativeWindow window)
 {
     lock (internalSyncObject)
     {
         uint         num;
         uint         num2;
         int          num5;
         uint         num3           = InitHash(handle, hashBuckets.Length, out num, out num2);
         int          num4           = 0;
         NativeWindow previousWindow = window.PreviousWindow;
         do
         {
             num5 = (int)(num % hashBuckets.Length);
             HandleBucket bucket = hashBuckets[num5];
             if (((bucket.hash_coll & 0x7fffffff) == num3) && (handle == bucket.handle))
             {
                 bool flag  = window.nextWindow == null;
                 bool flag2 = IsRootWindowInListWithChildren(window);
                 if (window.previousWindow != null)
                 {
                     window.previousWindow.nextWindow = window.nextWindow;
                 }
                 if (window.nextWindow != null)
                 {
                     window.nextWindow.defWindowProc  = window.defWindowProc;
                     window.nextWindow.previousWindow = window.previousWindow;
                 }
                 window.nextWindow     = null;
                 window.previousWindow = null;
                 if (flag2)
                 {
                     if (hashBuckets[num5].window.IsAllocated)
                     {
                         hashBuckets[num5].window.Free();
                     }
                     hashBuckets[num5].window = GCHandle.Alloc(previousWindow, GCHandleType.Weak);
                 }
                 else if (flag)
                 {
                     hashBuckets[num5].hash_coll &= -2147483648;
                     if (hashBuckets[num5].hash_coll != 0)
                     {
                         hashBuckets[num5].handle = new IntPtr(-1);
                     }
                     else
                     {
                         hashBuckets[num5].handle = IntPtr.Zero;
                     }
                     if (hashBuckets[num5].window.IsAllocated)
                     {
                         hashBuckets[num5].window.Free();
                     }
                     handleCount--;
                 }
                 break;
             }
             num += num2;
         }while ((hashBuckets[num5].hash_coll < 0) && (++num4 < hashBuckets.Length));
     }
 }
Beispiel #3
0
        private static void ExpandTable()
        {
            int length = hashBuckets.Length;
            int prime  = GetPrime(1 + (length * 2));

            HandleBucket[] bucketArray = new HandleBucket[prime];
            for (int i = 0; i < length; i++)
            {
                HandleBucket bucket = hashBuckets[i];
                if ((bucket.handle != IntPtr.Zero) && (bucket.handle != new IntPtr(-1)))
                {
                    uint num4 = (uint)(bucket.hash_coll & 0x7fffffff);
                    uint num5 = (uint)(1 + (((num4 >> 5) + 1) % (bucketArray.Length - 1)));
                    while (true)
                    {
                        int index = (int)(num4 % bucketArray.Length);
                        if ((bucketArray[index].handle == IntPtr.Zero) || (bucketArray[index].handle == new IntPtr(-1)))
                        {
                            bucketArray[index].window     = bucket.window;
                            bucketArray[index].handle     = bucket.handle;
                            bucketArray[index].hash_coll |= bucket.hash_coll & 0x7fffffff;
                            break;
                        }
                        bucketArray[index].hash_coll |= -2147483648;
                        num4 += num5;
                    }
                }
            }
            hashBuckets  = bucketArray;
            hashLoadSize = (int)(0.72f * prime);
            if (hashLoadSize >= prime)
            {
                hashLoadSize = prime - 1;
            }
        }
 private static void ExpandTable()
 {
     int length = hashBuckets.Length;
     int prime = GetPrime(1 + (length * 2));
     HandleBucket[] bucketArray = new HandleBucket[prime];
     for (int i = 0; i < length; i++)
     {
         HandleBucket bucket = hashBuckets[i];
         if ((bucket.handle != IntPtr.Zero) && (bucket.handle != new IntPtr(-1)))
         {
             uint num4 = (uint) (bucket.hash_coll & 0x7fffffff);
             uint num5 = (uint) (1 + (((num4 >> 5) + 1) % (bucketArray.Length - 1)));
             while (true)
             {
                 int index = (int) (num4 % bucketArray.Length);
                 if ((bucketArray[index].handle == IntPtr.Zero) || (bucketArray[index].handle == new IntPtr(-1)))
                 {
                     bucketArray[index].window = bucket.window;
                     bucketArray[index].handle = bucket.handle;
                     bucketArray[index].hash_coll |= bucket.hash_coll & 0x7fffffff;
                     break;
                 }
                 bucketArray[index].hash_coll |= -2147483648;
                 num4 += num5;
             }
         }
     }
     hashBuckets = bucketArray;
     hashLoadSize = (int) (0.72f * prime);
     if (hashLoadSize >= prime)
     {
         hashLoadSize = prime - 1;
     }
 }