Пример #1
0
        public void TestManyAsyncDisposalUsingWait()
        {
            var objects = new List <DisposableObject>();

            for (int i = 0; i < 10000; i++)
            {
                objects.Add(new DisposableObject());
            }

            objects.ForEach(AsyncDisposalQueue.Enqueue);

            AsyncDisposalQueue.WaitForEmpty();

            Assert.That(objects.All(o => o.IsDisposed));
        }
Пример #2
0
        protected override void Dispose(bool isDisposing)
        {
            // ensure any async disposals are completed before we begin to rip components out.
            // if we were to not wait, async disposals may throw unexpected exceptions.
            AsyncDisposalQueue.WaitForEmpty();

            base.Dispose(isDisposing);

            // call a second time to protect against anything being potentially async disposed in the base.Dispose call.
            AsyncDisposalQueue.WaitForEmpty();

            Audio?.Dispose();
            Audio = null;

            Fonts?.Dispose();
            Fonts = null;

            localFonts?.Dispose();
            localFonts = null;
        }