Beispiel #1
0
        public static void GraphicsDrawIconDoesNotLeakHandles()
        {
            RemoteExecutor.Invoke(() =>
            {
                const int handleTreshold = 1;
                using Bitmap bmp         = new(100, 100);
                using Icon ico           = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"));

                IntPtr hdc = Helpers.GetDC(Helpers.GetForegroundWindow());
                using Graphics graphicsFromHdc = Graphics.FromHdc(hdc);

                using Process currentProcess = Process.GetCurrentProcess();
                IntPtr processHandle         = currentProcess.Handle;

                int initialHandles = Helpers.GetGuiResources(processHandle, 0);
                ValidateNoWin32Error(initialHandles);

                for (int i = 0; i < 5000; i++)
                {
                    graphicsFromHdc.DrawIcon(ico, 100, 100);
                }

                int finalHandles = Helpers.GetGuiResources(processHandle, 0);
                ValidateNoWin32Error(finalHandles);

                Assert.InRange(finalHandles, initialHandles - handleTreshold, initialHandles + handleTreshold);
            }).Dispose();
        }
Beispiel #2
0
        public static IEnumerable <object[]> FromHdc_TestData()
        {
            yield return(new object[] { Helpers.GetDC(IntPtr.Zero) });

            yield return(new object[] { Helpers.GetWindowDC(IntPtr.Zero) });

            IntPtr foregroundWindow = Helpers.GetForegroundWindow();

            yield return(new object[] { Helpers.GetDC(foregroundWindow) });
        }