public override AsyncRequestElement PushAndOptionalPop(AsyncRequestElement req)
        {
            AsyncRequestElement popped = null;
            uint lowestRunningOrder    = uint.MaxValue;
            int  lowestRunningIdx      = -1;
            uint lowestCompletedOrder  = uint.MaxValue;
            int  lowestCompletedIdx    = -1;

            for (int i = 0; i < q.Length; i++)
            {
                popped = q[i];
                if (popped == null)
                {
                    q[i] = req.Start(order++);
                    return(null);
                }
                if (popped.IsCompleted)
                {
                    if (popped.queuedOrder >= lowestCompletedOrder)
                    {
                        continue;
                    }
                    lowestCompletedIdx = i;
                    continue;
                }
                if (popped.queuedOrder >= lowestRunningOrder)
                {
                    continue;
                }
                lowestRunningIdx = i;
            }

            //Pop and replace still running item
            int popIdx = lowestCompletedIdx;

            if (popIdx < 0)
            {
                popIdx = lowestRunningIdx;
            }
            popped    = q[popIdx];
            q[popIdx] = null;

            try
            {
                popped.EndInvoke();
            }
            finally
            {
                if (req != null)
                {
                    q[popIdx] = req.Start(order++);
                }
            }
            return(popped);
        }
        public override AsyncRequestElement PushAndOptionalPop(AsyncRequestElement req)
        {
            AsyncRequestElement popped = q;

            q = null;
            //dumpQ("before");
            try
            {
                if (popped != null)
                {
                    popped.EndInvoke();
                }
            }
            finally
            {
                if (req != null)
                {
                    q = req.Start(0);
                }
            }
            //dumpQ("after");
            return(popped);
        }