Example #1
0
        /**
         * Creates a new FuzzyEvent, Schedules it and returns it
         * @param todo the method to call
         * @param period_ms how long to wait between runs
         * @param latency_ms the acceptable latency for this call in milliseconds
         */
        public RepeatingFuzzyEvent DoEvery(System.Action <DateTime> todo, int period_ms, int latency_ms)
        {
            TimeSpan waitinterval = new TimeSpan(0, 0, 0, 0, period_ms);
            TimeSpan lat          = new TimeSpan(0, 0, 0, 0, latency_ms);

            DateTime            start     = DateTime.UtcNow + waitinterval;
            DateTime            end       = start + lat;
            RepeatingFuzzyEvent new_event = new RepeatingFuzzyEvent(todo, start, end, waitinterval);

            Schedule(new_event);
            return(new_event);
        }
Example #2
0
 //Run, and reschedule
 public override bool TryRun(DateTime now)
 {
     if (_flag.Value == false)
     {
         //We still have not canceled:
         _todo(now);
         //We have to make a new event because Interval<DateTime> has readonly
         //fields.  We pass the flag variable so share one big cancel variable
         var fe = new RepeatingFuzzyEvent(_todo, Start + _interval, End + _interval, _interval, _flag);
         FuzzyTimer.Instance.Schedule(fe);
         return(true);
     }
     else
     {
         return(false);
     }
 }