コード例 #1
0
 public void RemoveDispatcherObj(int key, IDynamicDispatcherObj dispatcherObj)
 {
     if (_listeners != null && _listeners.ContainsKey(key))
     {
         if (_isDispatching)
         {
             DynamicDispatcherObjEntry entry = _pool.GetObject();
             entry.DispatcherObj = dispatcherObj;
             entry.Status        = DynamicDispatcherObjEntry.EntryStatus.TODELETE;
             entry.Key           = key;
             _pendings.Add(entry);
         }
         else
         {
             SafeRemoveDispatcherObj(key, dispatcherObj);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// 监听事件
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="handler"></param>
        /// <param name="priorty"></param>
        public void AddDispatcherObj(int key, IDynamicDispatcherObj dispatcherObj, DynamicDispatcherObjEntry.EntryPriority priorty = DynamicDispatcherObjEntry.EntryPriority.NORMAL)
        {
            if (HasDispatcher(key, dispatcherObj))
            {
                return;
            }

            if (_listeners == null)
            {
                _listeners = new Dictionary <int, List <List <DynamicDispatcherObjEntry> > >();
            }

            if (!_listeners.ContainsKey(key))
            {
                _listeners[key] = new List <List <DynamicDispatcherObjEntry> >();
                List <List <DynamicDispatcherObjEntry> > allEntries = _listeners[key];
                int priorityCount = (int)DynamicDispatcherObjEntry.EntryPriority.COUNT;
                for (int i = 0; i < priorityCount; ++i)
                {
                    List <DynamicDispatcherObjEntry> entries = new List <DynamicDispatcherObjEntry>();
                    allEntries.Add(entries);
                }
            }

            DynamicDispatcherObjEntry entry = _pool.GetObject();

            entry.DispatcherObj = dispatcherObj;
            entry.Priority      = priorty;
            entry.Key           = key;

            if (_isDispatching)
            {
                entry.Status = DynamicDispatcherObjEntry.EntryStatus.TOINSERT;
                _pendings.Add(entry);
            }
            else
            {
                entry.Status = DynamicDispatcherObjEntry.EntryStatus.ACTIVE;
                List <List <DynamicDispatcherObjEntry> > allEntries = _listeners[key];

                List <DynamicDispatcherObjEntry> entries = allEntries[(int)priorty];
                entries.Add(entry);
            }
        }