コード例 #1
0
ファイル: Gateway.cs プロジェクト: xiaguoli/IoTGateway
 /// <summary>
 /// Schedules a one-time event.
 /// </summary>
 /// <param name="Callback">Method to call when event is due.</param>
 /// <param name="When">When the event is to be executed.</param>
 /// <param name="State">State object</param>
 /// <returns>Timepoint of when event was scheduled.</returns>
 public static DateTime ScheduleEvent(ScheduledEventCallback Callback, DateTime When, object State)
 {
     if (scheduler != null)
     {
         return(scheduler.Add(When, Callback, State));
     }
     else
     {
         return(DateTime.MinValue);
     }
 }
コード例 #2
0
ファイル: Scheduler.cs プロジェクト: orf53975/IoTGateway
        /// <summary>
        /// Adds an event.
        /// </summary>
        /// <param name="When">When to execute the event.</param>
        /// <param name="Callback">Method called when event is to be executed.</param>
        /// <param name="State">State object bassed to <paramref name="Callback"/>.</param>
        /// <returns>Time when event was scheduled. May differ from <paramref name="When"/> by a few ticks, to make sure the timestamp is unique.</returns>
        public DateTime Add(DateTime When, ScheduledEventCallback Callback, object State)
        {
            lock (this.events)
            {
                while (this.events.ContainsKey(When))
                {
                    When = When.AddTicks(this.gen.Next(1, 10));
                }

                this.events[When] = new ScheduledEvent(When, Callback, State);
                this.RecalcTimerLocked();
            }

            return(When);
        }
コード例 #3
0
ファイル: EventScheduler.cs プロジェクト: dawolfen/MintChip
        // where T : ScheduledEventCallbackInfo
        /// <summary>Schedule an event to occur. The callback will be invoked with the provided parameters</summary>
        /// <returns>A unique identifier such that it can be cancelled later</returns>
        public Guid ScheduleEvent(DateTime scheduleTime, ScheduledEventCallback callback, ScheduledEventCallbackInfo callbackInfo)
        {
            PerformDisposedCheck();

            lock (lockObj)
            {
                List<object> list = null;

                if (this.scheduleTable.ContainsKey(scheduleTime))
                    list = this.scheduleTable[scheduleTime];
                else
                {
                    list = new List<object>();
                    this.scheduleTable[scheduleTime] = list;
                }

                Guid guid = Guid.NewGuid();

                list.Add(new object[] {callback, callbackInfo, guid});

                if (scheduleTime < nextScheduledItem)
                {
                    // wake up the scheduler to update the schedule and possibly notify
                    Monitor.PulseAll(lockObj);
                }

                return guid;
            }
        }
コード例 #4
0
 /// <summary>
 /// Contains information about a scheduled event.
 /// </summary>
 /// <param name="When">When an event is to be executed.</param>
 /// <param name="EventMethod">Method to call when event is executed.</param>
 /// <param name="State">State object passed on to <paramref name="EventMethod"/>.</param>
 public ScheduledEvent(DateTime When, ScheduledEventCallback EventMethod, object State)
 {
     this.when        = When;
     this.eventMethod = EventMethod;
     this.state       = State;
 }
コード例 #5
0
ファイル: ScheduledEvent.cs プロジェクト: iamr8/IoTGateway
 /// <summary>
 /// Contains information about a scheduled event.
 /// </summary>
 /// <param name="When">When an event is to be executed.</param>
 /// <param name="EventMethod">Method to call when event is executed.</param>
 /// <param name="State">State object passed on to <paramref name="EventMethod"/>.</param>
 public ScheduledEvent(DateTime When, ScheduledEventCallbackAsync EventMethod, object State)
 {
     this.when        = When;
     this.eventMethod = this.AsyncCallback;
     this.state       = new object[] { EventMethod, State };
 }