コード例 #1
0
        public void AllowMultipleDisposals()
        {
            var target = new CancellationSource();

            target.Dispose();

            Assert.DoesNotThrow(() => target.Dispose());
        }
コード例 #2
0
        public void IndicatesCancellationWhenImmediate()
        {
            using var target = new CancellationSource();
            Assert.False(target.IsCancellationRequested);

            target.RequestImmediateCancellation();

            Assert.True(target.IsCancellationRequested);
        }
コード例 #3
0
        public void IndicatesCancellationWhenAfterAPeriodOfTime()
        {
            using var target = new CancellationSource();
            Assert.False(target.IsCancellationRequested);

            target.RequestCancellationAfter(TimeSpan.FromSeconds(1));

            Thread.Sleep(TimeSpan.FromSeconds(2));

            Assert.True(target.IsCancellationRequested);
        }