예제 #1
0
        public void StressTest()
        {
            Font[] fonts = new Font[10];
            for (int i = 0; i < 10; i++)
            {
                fonts[i] = new Font("Arial", i + 6);
            }

            FontCache cache  = new FontCache(softLimit: 4, hardLimit: 8);
            Random    random = new Random();

            try
            {
                for (int i = 0; i < 10_000; i++)
                {
                    Thread.Sleep(random.Next(5));
                    Task.Run(() =>
                    {
                        using var hfont = cache.GetHFONT(
                                  fonts[random.Next(10)],
                                  (Gdi32.QUALITY)random.Next(7));

                        Assert.False(hfont.HFONT.IsNull);
                        Thread.Sleep(random.Next(10));
                    });
                }
            }
            finally
            {
                cache.Dispose();
                for (int i = 0; i < 10; i++)
                {
                    fonts[i]?.Dispose();
                }
            }
        }