コード例 #1
0
        public void Bind(IoCache <TPacket> ioCache)
        {
            ioCache.PacketCacheInfoCollection.CollectionChanged += (sender, e) =>
            {
                switch (e.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                {
                    foreach (var item in e.NewItems)
                    {
                        _timer.Add((PacketCacheInfo <TPacket>)item, new Timer((state) =>
                            {
                                lock (ioCache.PacketCacheInfoCollection)
                                {
                                    ioCache.PacketCacheInfoCollection.Remove((PacketCacheInfo <TPacket>)state);
                                }
                            }, (PacketCacheInfo <TPacket>)item, ExpireTime, Timeout.InfiniteTimeSpan));
                    }

                    break;
                }

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                {
                    foreach (var item in e.OldItems)
                    {
                        _timer[(PacketCacheInfo <TPacket>)item].Dispose();
                        _timer.Remove((PacketCacheInfo <TPacket>)item);
                    }

                    break;
                }
                }
            };
        }
コード例 #2
0
 public void Bind(IoCache <TPacket> ioCache)
 {
     ioCache.Channel.DataReceived += (sender, arg) =>
     {
         if (ioCache.PacketCacheInfoCollection.Count > CacheCount)
         {
             lock (ioCache.PacketCacheInfoCollection)
             {
                 ioCache.PacketCacheInfoCollection.RemoveAt(0);
             }
         }
     };
 }
コード例 #3
0
 public void Bind(IoCache <TPacket> ioCache)
 {
     ioCache.PacketCacheInfoCollection.CollectionChanged += (sender, e) =>
     {
         if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
         {
             if (ioCache.PacketCacheInfoCollection.Count > CacheCount)
             {
                 Task.Run(() => ioCache.PacketCacheInfoCollection.RemoveAt(0));
             }
         }
     };
 }
コード例 #4
0
 public void Bind(IoCache <TPacket> ioCache)
 {
     ioCache.PacketCacheInfoCollection.CollectionChanged += (sender, e) =>
     {
         if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
         {
             foreach (var item in e.NewItems)
             {
                 _timer.Add((PacketCacheInfo <TPacket>)item, new Timer((state) => ioCache.PacketCacheInfoCollection.Remove((PacketCacheInfo <TPacket>)state), (PacketCacheInfo <TPacket>)item, ExpireTime, Timeout.InfiniteTimeSpan));
             }
         }
         if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
         {
             foreach (var item in e.OldItems)
             {
                 _timer.Remove((PacketCacheInfo <TPacket>)item);
             }
         }
     };
 }