private static void ExecutePending(SafeQueue <Action> queue, RuntimeUniqueIdProdiver.UniqueId id)
        {
            var didEnter = false;

            try
            {
                didEnter = ReentryGuardHelper.Enter(id);
                if (!didEnter)
                {
                    // called from inside this method - skip
                    return;
                }
                Action action;
                while (queue.TryTake(out action))
                {
                    action.Invoke();
                }
            }
            finally
            {
                if (didEnter)
                {
                    ReentryGuardHelper.Leave(id);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReentryGuard" /> class.
 /// </summary>
 public ReentryGuard()
 {
     _workQueue = new SafeQueue <Action>();
     _id        = RuntimeUniqueIdProdiver.GetNextId();
 }