Пример #1
0
    public bool Block(object obj, bool increaseBlock = true)
    {
        if (obj == null)
        {
            return(false);
        }

        bool trigger = Free;

        SemaphoreObject s;
        bool            newKey = !_semaphores.TryGetValue(obj, out s);

        if (newKey || increaseBlock)
        {
            if (newKey)
            {
                s = new SemaphoreObject();
                _semaphores.Add(obj, s);
            }
            s.Value++;
        }

        if (trigger)
        {
            _blockEvent.Trigger();
            _changeStateEvent.Trigger(false);
        }

        _onInteraction.Trigger();

        return(newKey);
    }
Пример #2
0
 private static void TryRemoveSemaphore(string name, SemaphoreObject o)
 {
     o.Obj.Release();
     if (o.SemaphoreCountAdd(-1).LockCount == 0)
     {
         SemaphoreDict.TryRemove(name, out _);
     }
 }