예제 #1
0
    public void Release()
    {
        CallbackObject execute = null;

        if (Interlocked.Increment(ref this.counter) < 0)
        {
            if (!queue.TryDequeue(out execute))
            {
                throw new NotImplementedException("ConcurrentQueue.TryDequeue failed");
            }
        }
        else
        {
            if (counter > maxCounter)
            {
                throw new SemaphoreFullException("Release was called too many times");
            }
        }

        if (execute != null)
        {
            execute.Callback(execute);
            execute.IsCompleted = true;
        }
    }
    public void Release()
    {
        CallbackObject execute = null;

        lock (this)
        {
            if (!queue.Any())
            {
                if (++counter > maxCounter)
                {
                    throw new SemaphoreFullException("Release was called too many times");
                }
            }
            else
            {
                execute = queue.Dequeue();
            }
        }
        if (execute != null)
        {
            execute.Callback(execute);
            execute.IsCompleted = true;
        }
    }