Start() public method

Start the task.
public Start ( Func elapsed ) : void
elapsed Func The task to run.
return void
Example #1
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();
            }
Example #2
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));
            }
Example #3
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 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 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));
            }