Ejemplo n.º 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));
            }
        }
Ejemplo n.º 2
0
        public void CanUpdateThrottlingTime()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(3)))
            {
                mre.Update(TimeSpan.FromSeconds(7));

                Assert.Equal(TimeSpan.FromSeconds(7), mre.ThrottlingInterval);

                mre.Set();

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

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(9).TotalMilliseconds, CancellationToken.None));
            }
        }
Ejemplo n.º 3
0
        public void WillSetMreOnTime()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(5)))
            {
                mre.Set();

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