Runs a task after a certain delay and log any error.
Inheritance: IDisposable
Exemple #1
0
            public void CanBeSetToInfiniteToPreventTimerFromFiring()
            {
                var timer = new TaskTimer();

                timer.Delay = new TimeSpan(0, 0, 0, 0, -1);
                Assert.Equal(new TimeSpan(0, 0, 0, 0, -1), timer.Delay);
            }
Exemple #2
0
            public void CanBeChangedByConfigurableChannelComponents()
            {
                var timer = new TaskTimer();

                timer.Delay = TimeSpan.FromSeconds(42);
                Assert.Equal(42, timer.Delay.TotalSeconds);
            }
Exemple #3
0
            public void ReturnsTrueWhileUntilActionIsInvoked()
            {
                var timer = new TaskTimer {
                    Delay = TimeSpan.FromMilliseconds(1)
                };

                var actionStarted   = new ManualResetEventSlim();
                var actionCanFinish = new ManualResetEventSlim();

                timer.Start(
                    () => Task.Factory.StartNew(
                        () =>
                {
                    actionStarted.Set();
                    actionCanFinish.Wait();
                }));

                Assert.True(timer.IsStarted);

                actionStarted.Wait(50);

                Assert.False(timer.IsStarted);

                actionCanFinish.Set();
            }
Exemple #4
0
            public void InvokesActionAfterDelay()
            {
                var timer = new TaskTimer {
                    Delay = TimeSpan.FromMilliseconds(1)
                };

                var actionInvoked = new ManualResetEventSlim();

                timer.Start(() => Task.Factory.StartNew(actionInvoked.Set));

                Assert.False(actionInvoked.IsSet);
                Assert.True(actionInvoked.Wait(50));
            }
Exemple #5
0
            public void AbortsPreviousAction()
            {
                AsyncTest.Run(async() =>
                {
                    var timer = new TaskTimer {
                        Delay = TimeSpan.FromMilliseconds(1)
                    };

                    bool actionInvoked = false;
                    timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true));
                    timer.Cancel();

                    await TaskEx.Delay(20);

                    Assert.False(actionInvoked);
                });
            }
            public void ReturnsTrueWhileUntilActionIsInvoked()
            {
                var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) };

                var actionStarted = new ManualResetEventSlim();
                var actionCanFinish = new ManualResetEventSlim();
                timer.Start(
                    () => Task.Factory.StartNew(
                        () =>
                            {
                                actionStarted.Set();
                                actionCanFinish.Wait();
                            }));

                Assert.True(timer.IsStarted);

                actionStarted.Wait(50);

                Assert.False(timer.IsStarted);

                actionCanFinish.Set();
            }
            public void InvokesActionAfterDelay()
            {
                var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) };

                var actionInvoked = new ManualResetEventSlim();
                timer.Start(() => Task.Factory.StartNew(actionInvoked.Set));

                Assert.False(actionInvoked.IsSet);
                Assert.True(actionInvoked.Wait(50));
            }
 public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsMoreThanMaxIntMilliseconds()
 {
     var timer = new TaskTimer();
     Assert.Throws<ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.FromMilliseconds((double)int.MaxValue + 1));
 }
 public void ReturnsFalseIfTimerWasNeverStarted()
 {
     var timer = new TaskTimer();
     Assert.False(timer.IsStarted);
 }
 public void CanBeSetToInfiniteToPreventTimerFromFiring()
 {
     var timer = new TaskTimer();
     timer.Delay = new TimeSpan(0, 0, 0, 0, -1);
     Assert.Equal(new TimeSpan(0, 0, 0, 0, -1), timer.Delay);
 }
 public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsZeroOrLess()
 {
     var timer = new TaskTimer();
     Assert.Throws<ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.Zero);
 }
 public void DefaultValueIsOneMinuteBecauseItHasToBeSomethingValid()
 {
     var timer = new TaskTimer();
     Assert.Equal(TimeSpan.FromMinutes(1), timer.Delay);
 }
 public void CanBeChangedByConfigurableChannelComponents()
 {
     var timer = new TaskTimer();
     timer.Delay = TimeSpan.FromSeconds(42);
     Assert.Equal(42, timer.Delay.TotalSeconds);
 }
     public void AbortsPreviousAction()
     {
         AsyncTest.Run(async () =>
         {
             var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) };
 
             bool actionInvoked = false;
             timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true));
             timer.Cancel();
 
             await TaskEx.Delay(20);
 
             Assert.False(actionInvoked);
         });
     }
Exemple #15
0
            public void DefaultValueIsOneMinuteBecauseItHasToBeSomethingValid()
            {
                var timer = new TaskTimer();

                Assert.Equal(TimeSpan.FromMinutes(1), timer.Delay);
            }
Exemple #16
0
            public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsZeroOrLess()
            {
                var timer = new TaskTimer();

                Assert.Throws <ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.Zero);
            }
Exemple #17
0
            public void ReturnsFalseIfTimerWasNeverStarted()
            {
                var timer = new TaskTimer();

                Assert.False(timer.IsStarted);
            }
Exemple #18
0
            public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsMoreThanMaxIntMilliseconds()
            {
                var timer = new TaskTimer();

                Assert.Throws <ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.FromMilliseconds((double)int.MaxValue + 1));
            }