コード例 #1
0
        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);
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
 //------------------
 private void FireCommandAddedEvent(OwlCommand c)
 {
     CommandAdded?.Invoke(this, c);
     FireQueueChangedEvent();
 }
コード例 #4
0
 public void Add(OwlCommand c)
 {
     Add(c, false);
 }
コード例 #5
0
 public int Remove(OwlCommand c)
 {
     return(Remove(c.Id));
 }