Beispiel #1
0
        public static TimeEvent Add(TimeSpan time, object obj, TimeEvent.callback callbackFunc)
        {
            TimeEvent te;

            te = Instance().privAddEvent(time, obj, callbackFunc);
            return(te);
        }
Beispiel #2
0
        // private: unique methods for this class: ------------------------------------------------------

        private TimeEvent privAddEvent(TimeSpan _time, object obj, TimeEvent.callback _callbackFunc)
        {
            // Do we need to get more TimeEvents?

            if (this.inActive == null)
            {
                // fill pool with more nodes
                // OK now preload the timeEvents
                this.privFillPool(this.deltaGrow);
            }

            // make sure we have TimeEvents

            Debug.Assert(this.inActive != null);

            // Detach 1 TimeEvent from the pool

            TimeEvent te;

            te = privInActiveGetNodeFromFront(ref this.inActive);

            // Initialize our TimeEvent

            te.next   = null;
            te.prev   = null;
            te.dataCB = obj;
            te.time   = _time;
            te.funcCB = _callbackFunc;

            // need to add the TimeEvent to active;

            // insert in TimeSpan order (lowest closes to head)

            TimeEvent pEvent = this.active;

            if (this.active == null)
            {
                // nothing on the list, just insert
                this.active = te;
            }
            else
            {
                // walk the list and insert before
                TimeEvent LastEvent = pEvent;
                while (pEvent != null)
                {
                    if (te.time <= pEvent.time)
                    {
                        // insert before pEvent
                        break;
                    }
                    // goto next
                    LastEvent = pEvent;
                    pEvent    = pEvent.next;
                }

                // add the new event to active list
                if (pEvent != null)
                {
                    // install before
                    if (pEvent.prev == null)
                    {
                        // 1st on list
                        te.next          = this.active;
                        this.active.prev = te;
                        this.active      = te;
                    }
                    else
                    {
                        // middle of list
                        LastEvent.next = te;
                        te.prev        = LastEvent;
                        pEvent.prev    = te;
                        te.next        = pEvent;
                    }
                }
                else
                {
                    // install after: (last on list)
                    LastEvent.next = te;
                    te.prev        = LastEvent;
                }
            }

            return(te);
        }