void RunFrame(DispatcherFrame frame)
        {
            do
            {
                while (queue_bits != 0)
                {
                    for (int i = TOP_PRIO; i > 0 && queue_bits != 0; i--)
                    {
                        int current_bit = queue_bits & (1 << i);
                        if (current_bit != 0)
                        {
                            PokableQueue q = priority_queues [i];

                            do
                            {
                                DispatcherOperation task;

                                lock (q)
                                {
                                    task = (DispatcherOperation)q.Dequeue();
                                }

                                task.Invoke();

                                //
                                // call hooks.
                                //
                                if (task.Status == DispatcherOperationStatus.Aborted)
                                {
                                    hooks.EmitOperationAborted(task);
                                }
                                else
                                {
                                    hooks.EmitOperationCompleted(task);
                                }

                                if (!frame.Continue)
                                {
                                    return;
                                }

                                if (HasShutdownStarted)
                                {
                                    PerformShutdown();
                                    return;
                                }

                                // if we are done with this queue, leave.
                                lock (q)
                                {
                                    if (q.Count == 0)
                                    {
                                        queue_bits &= ~(1 << i);
                                        break;
                                    }
                                }

                                //
                                // If a higher-priority task comes in, go do that
                                //
                                if (current_bit < (queue_bits & ~current_bit))
                                {
                                    break;
                                }
                            }while (true);
                        }
                    }
                }
                hooks.EmitInactive();

                wait.WaitOne();
                wait.Reset();
            }while (frame.Continue);
        }