Beispiel #1
0
        int Index(DelayedBehaviour action)
        {
            var index = actions.BinarySearch(action);

            if (index < 0)
            {
                return(~index);
            }
            while (index < actions.Count && action.CompareTo(actions[index]) >= 0)
            {
                index++;
            }
            return(index);
        }
Beispiel #2
0
        public void Add(Action a, long desiredTime)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }

            lock (actions)
            {
                var action = new DelayedBehaviour(a, desiredTime);
                var index  = Index(action);
                actions.Insert(index, action);
            }
        }
Beispiel #3
0
        public void PerformActions(long currentTime)
        {
            DelayedBehaviour[] pendingActions;
            lock (actions)
            {
                var dummyAction = new DelayedBehaviour(null, currentTime);
                var index       = Index(dummyAction);
                if (index <= 0)
                {
                    return;
                }

                pendingActions = new DelayedBehaviour[index];
                actions.CopyTo(0, pendingActions, 0, index);
                actions.RemoveRange(0, index);
            }

            foreach (var delayedAction in pendingActions)
            {
                delayedAction.Action();
            }
        }