protected OwlCommand GetNext(bool remove) { OwlCommand next = null; _lock.EnterUpgradeableReadLock(); try { if (_commandList.Count > 0) { next = _commandList.First(); if (remove) { _lock.EnterWriteLock(); try { _commandList.Remove(next); FireQueueChangedEvent(); if (_commandList.Count == 0) { FireQueueEmptyEvent(); } } finally { if (_lock.IsWriteLockHeld) { _lock.ExitWriteLock(); } } } } } catch (Exception exAny) { //Log something? throw; } finally { if (_lock.IsUpgradeableReadLockHeld) { _lock.ExitUpgradeableReadLock(); } } return(next); }
public void Add(OwlCommand c, bool insertAtFront) { _lock.EnterUpgradeableReadLock(); try { List <OwlCommand> found = _commandList.FindAll(x => x.Id == c.Id); if (found.Count == 0) { _lock.EnterWriteLock(); } try { if (insertAtFront) { _commandList.Insert(0, c); } else { _commandList.Add(c); } FireCommandAddedEvent(c); } finally { if (_lock.IsWriteLockHeld) { _lock.ExitWriteLock(); } } } catch (Exception exAny) { //Log something? throw; } finally { if (_lock.IsUpgradeableReadLockHeld) { _lock.ExitUpgradeableReadLock(); } } }
//------------------ private void FireCommandAddedEvent(OwlCommand c) { CommandAdded?.Invoke(this, c); FireQueueChangedEvent(); }
public void Add(OwlCommand c) { Add(c, false); }
public int Remove(OwlCommand c) { return(Remove(c.Id)); }