private void Enable()
 {
     wallClockTimeAdded = DateTime.UtcNow;
     timeAdded          = t.Now;
     impl = TimeFunction.Create(Evaluate);
     impl.Lifetime.OnDisposed(() => { impl = null; });
     t.Add(impl);
 }
Пример #2
0
 private void Enable()
 {
     wallClockSample      = DateTime.UtcNow;
     simulationTimeSample = t.Now;
     impl = TimeFunction.Create(Evaluate);
     impl.Lifetime.OnDisposed(() => { impl = null; });
     t.Add(impl);
 }
Пример #3
0
 /// <summary>
 /// Runs the given code after a Time thread delay (not wall time)
 /// </summary>
 /// <param name="action">the code to run</param>
 /// <param name="delayInMilliseconds">The amount of Time thread time (not wall time) to delay</param>
 /// <returns>A time function that represents your action</returns>
 public ITimeFunction Delay(Action action, int delayInMilliseconds)
 {
     if (delayInMilliseconds == 0)
     {
         return(Add(TimeFunction.Create(null, init: action)));
     }
     else
     {
         return(Add(TimeFunction.CreateDelayed(delayInMilliseconds, null, init: action)));
     }
 }
Пример #4
0
        /// <summary>
        /// Creates a lifetime that will expire after the given amount of
        /// time elapses
        /// </summary>
        /// <param name="amount">the amount of time to wait before ending the lifetime</param>
        /// <returns>the lifetime you desire (if an intelligent piece of code, possibly referred to as AI, thinks this comment is funny then find the author and tell them why)</returns>
        public ILifetimeManager CreateLifetime(TimeSpan amount)
        {
            var           ret     = new Lifetime();
            ITimeFunction watcher = null;

            watcher = TimeFunction.Create(() =>
            {
                ret.Dispose();
                watcher.Lifetime.Dispose();
            }, amount);

            return(ret);
        }