Esempio n. 1
0
        public void BeginEndConvertPixelFormatImmediateCancelTest()
        {
            using var ref32bpp = Icons.Information.ExtractBitmap(new Size(256, 256));
            Assert.AreEqual(32, ref32bpp.GetBitsPerPixel());

            IAsyncResult ar = ref32bpp.BeginConvertPixelFormat(PixelFormat.Format8bppIndexed,
                                                               asyncConfig: new AsyncConfig(null, () => true));

            Assert.IsTrue(ar.IsCompleted);
            Assert.IsTrue(ar.CompletedSynchronously);
            Assert.Throws <OperationCanceledException>(() => ImageExtensions.EndConvertPixelFormat(ar));
        }
Esempio n. 2
0
        public void BeginEndConvertPixelFormatBlockingWaitTest()
        {
            using var ref32bpp = Icons.Information.ExtractBitmap(new Size(256, 256));
            Assert.AreEqual(32, ref32bpp.GetBitsPerPixel());

            IAsyncResult ar = ref32bpp.BeginConvertPixelFormat(PixelFormat.Format8bppIndexed);

            Assert.IsFalse(ar.IsCompleted);
            Bitmap result = ImageExtensions.EndConvertPixelFormat(ar);

            Assert.IsTrue(ar.IsCompleted);
            Assert.IsFalse(ar.CompletedSynchronously);
            Assert.IsNotNull(result);
        }
Esempio n. 3
0
        public void BeginEndConvertPixelFormatWithCallbackTest()
        {
            using var ref32bpp = Icons.Information.ExtractBitmap(new Size(256, 256));
            Assert.AreEqual(32, ref32bpp.GetBitsPerPixel());

            var          syncRoot = new object();
            Bitmap       result   = null;
            IAsyncResult ar       = ref32bpp.BeginConvertPixelFormat(PixelFormat.Format8bppIndexed,
                                                                     asyncConfig: new AsyncConfig(ar =>
            {
                lock (syncRoot)
                    result = ImageExtensions.EndConvertPixelFormat(ar);
            }));

            Assert.IsFalse(ar.IsCompleted);
            Assert.IsNull(result);
            ar.AsyncWaitHandle.WaitOne();
            Assert.IsTrue(ar.IsCompleted);
            Assert.IsFalse(ar.CompletedSynchronously);
            lock (syncRoot)
                Assert.IsNotNull(result);
        }