コード例 #1
0
        public void CanEnableDisableThrottlingTimer()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(1), timerManagement: ThrottledManualResetEventSlim.TimerManagement.Manual))
            {
                mre.Set();

                Assert.False(mre.Wait((int)TimeSpan.FromSeconds(3).TotalMilliseconds, CancellationToken.None));

                mre.EnableThrottlingTimer();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(2).TotalMilliseconds, CancellationToken.None));

                mre.Reset();

                mre.DisableThrottlingTimer();

                Assert.False(mre.IsSet);

                mre.Set();

                Assert.False(mre.Wait((int)TimeSpan.FromSeconds(3).TotalMilliseconds, CancellationToken.None));

                mre.EnableThrottlingTimer();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(2).TotalMilliseconds, CancellationToken.None));
            }
        }
コード例 #2
0
        public void ShouldSetMreImmediatelyWhenThrottlingDisabled()
        {
            using (var mre = new ThrottledManualResetEventSlim(null))
            {
                Assert.Null(mre.ThrottlingInterval);

                mre.Set();

                Assert.True(mre.IsSet);

                mre.Reset();

                Assert.False(mre.IsSet);
            }
        }