public void TestSleep()
        {
            WakeUpCommand      wakeup = new WakeUpCommand();
            ActiveObjectEngine e      = new ActiveObjectEngine();

            // Building multithreaded systems using variations of this technique has been, and will continue to be, a
            // very common practice.Threads of this kind have been known as run - to - completion tasks(RTC);
            // each Command instance runs to completion before the next Command instance can run.The name RTC
            // implies that the Command instances do not block.

            // The fact that the Command instances all run to completion gives RTC threads the interesting advantage
            // that they all share the same runtime stack. Unlike the threads in a traditional multithreaded system,
            // it is not necessary to define or allocate a separate runtime stack for each RTC thread.This can be a
            // powerful advantage in memory - constrained systems with many threads.


            SleepCommand c = new SleepCommand(1000, e, wakeup);

            e.AddCommand(c);
            DateTime start = DateTime.Now;

            e.Run();
            DateTime stop      = DateTime.Now;
            double   sleepTime = (stop - start).TotalMilliseconds;

            Assert.IsTrue(sleepTime >= 1000, "SleepTime " + sleepTime + " expected > 1000");
            Assert.IsTrue(sleepTime <= 1100, "SleepTime " + sleepTime + " expected < 1100");
            Assert.IsTrue(wakeup.executed, "Command Executed");
        }
 public SleepCommand(long milliseconds, ActiveObjectEngine e, Command wakeupCommand)
 {
     sleepTime          = milliseconds;
     engine             = e;
     this.wakeupCommand = wakeupCommand;
 }