CEventListComparer

    internal class CEventListComparer : IComparer<DateTime>
    {
        static private CEventListComparer mono;
        public static CEventListComparer EarlyFirst
        {
            get
            {
                if (mono == null)
                    mono = new CEventListComparer();
                return mono;
            }
        }

        #region IComparer
        public int Compare(DateTime x, DateTime y)
        {
            if (x == y)
                return -1;
            else if (x < y)
                return -1;
            else
                return 1;
        }
        #endregion
    }

    internal class CEventList : SortedList<DateTime, IScheduleable>
    {
        public CEventList()
            : base(CEventListComparer.EarlyFirst)
        {
        }

        public IScheduleable PopEarlistSchedule(out DateTime newTime)
        {
            IScheduleable ish = null;
            IEnumerator<KeyValuePair<DateTime, IScheduleable>> getFirst = GetEnumerator();
            getFirst.MoveNext();
            newTime = getFirst.Current.Key;
            ish = getFirst.Current.Value;
            RemoveAt(0);
            return ish;
        }

        internal void Schedule(DateTime ScheduledTime, IScheduleable ScheduledCall)
        {
            Add(ScheduledTime, ScheduledCall);
        }
    }

你可能感兴趣的:(CEventListComparer)