Example #1
0
        public void SingleShotTimer_Elapsed_CanChangeToPeriodic()
        {
            bool autoReset = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer          = new Timer();
                    timer.Elapsed += () =>
                    {
                        timer.SetPeriodic(timer.Interval);
                        autoReset = timer.AutoReset;
                        timer.Cancel();
                    };
                    timer.AutoReset = false;
                    timer.Interval  = TimeSpan.FromMilliseconds(0);
                    timer.Enabled   = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.IsTrue(autoReset, "Single-shot Timer should be able to change to Periodic within Elapsed");
        }
Example #2
0
        public void TimerType_AfterSetPeriodic_IsPeriodic()
        {
            bool autoReset = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() =>
                {
                    using (Timer timer = new Timer())
                    {
                        timer.SetPeriodic(TimeSpan.FromMilliseconds(50));
                        autoReset = timer.AutoReset;
                    }
                });
            }

            Assert.IsTrue(autoReset, "Timer should be periodic");
        }
Example #3
0
        public void Timer_AfterSetPeriodic_IsEnabled()
        {
            bool enabled = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() =>
                {
                    using (Timer timer = new Timer())
                    {
                        timer.SetPeriodic(TimeSpan.FromMilliseconds(50));
                        enabled = timer.Enabled;
                    }
                });
            }

            Assert.IsTrue(enabled, "Timer.Enabled should be true");
        }
Example #4
0
        public void Timer_AfterSetPeriodic_IsEnabled()
        {
            bool enabled = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() =>
                {
                    using (Timer timer = new Timer())
                    {
                        timer.SetPeriodic(TimeSpan.FromMilliseconds(50));
                        enabled = timer.Enabled;
                    }
                });
            }

            Assert.IsTrue(enabled, "Timer.Enabled should be true");
        }
Example #5
0
        public void TimerType_AfterSetPeriodic_IsPeriodic()
        {
            bool autoReset = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                thread.DoSynchronously(() =>
                {
                    using (Timer timer = new Timer())
                    {
                        timer.SetPeriodic(TimeSpan.FromMilliseconds(50));
                        autoReset = timer.AutoReset;
                    }
                });
            }

            Assert.IsTrue(autoReset, "Timer should be periodic");
        }
Example #6
0
        public void SingleShotTimer_Elapsed_CanChangeToPeriodic()
        {
            bool autoReset = false;

            using (ActionThread thread = new ActionThread())
            {
                thread.Start();
                Timer timer = null;
                thread.DoSynchronously(() =>
                {
                    timer = new Timer();
                    timer.Elapsed += () =>
                    {
                        timer.SetPeriodic(timer.Interval);
                        autoReset = timer.AutoReset;
                        timer.Cancel();
                    };
                    timer.AutoReset = false;
                    timer.Interval = TimeSpan.FromMilliseconds(0);
                    timer.Enabled = true;
                });
                Thread.Sleep(10);
                thread.DoSynchronously(() => timer.Dispose());
            }

            Assert.IsTrue(autoReset, "Single-shot Timer should be able to change to Periodic within Elapsed");
        }