private void DeleteMinTimerCore()

in iothub/service/src/net451/Common/IOThreadTimer.cs [508:581]


            private void DeleteMinTimerCore()
            {
                int currentCount = Count;

                if (currentCount == 1)
                {
                    Count = 0;
                    _timers[1] = null;
                }
                else
                {
                    IOThreadTimer[] tempTimers = _timers;
                    IOThreadTimer lastTimer = tempTimers[currentCount];
                    Count = --currentCount;

                    int index = 1;
                    while (true)
                    {
                        int leftChildIndex = index * 2;

                        if (leftChildIndex > currentCount)
                        {
                            break;
                        }

                        int childIndex;
                        IOThreadTimer child;

                        if (leftChildIndex < currentCount)
                        {
                            IOThreadTimer leftChild = tempTimers[leftChildIndex];
                            int rightChildIndex = leftChildIndex + 1;
                            IOThreadTimer rightChild = tempTimers[rightChildIndex];

                            if (rightChild._dueTime < leftChild._dueTime)
                            {
                                child = rightChild;
                                childIndex = rightChildIndex;
                            }
                            else
                            {
                                child = leftChild;
                                childIndex = leftChildIndex;
                            }
                        }
                        else
                        {
                            childIndex = leftChildIndex;
                            child = tempTimers[childIndex];
                        }

                        if (lastTimer._dueTime > child._dueTime)
                        {
                            tempTimers[index] = child;
                            child._index = index;
                        }
                        else
                        {
                            break;
                        }

                        index = childIndex;

                        if (leftChildIndex >= currentCount)
                        {
                            break;
                        }
                    }

                    tempTimers[index] = lastTimer;
                    lastTimer._index = index;
                    tempTimers[currentCount + 1] = null;
                }
            }