private int _maxWriteCount = 10000; //允许写的最大数量 /// <summary> /// /// </summary> /// <param name="maxWriteCount">允许写的最大数量</param> /// <param name="handleMessage">处理的方法</param> /// <param name="handNoCount">当前队列没有没有消息的处理方法,在单次处理完之后调用</param> public BufferQueue(int maxWriteCount, Action <TMessage> handleMessage, Action handNoCount = null) { EnsureUtil.NotNull(handleMessage, "处理方法不能为空"); _maxWriteCount = maxWriteCount; _messageQueue = new ConcurrentQueue <TMessage>(); _handleMessage = handleMessage; _handNoCount = handNoCount; }
/// <summary> /// .ctor /// </summary> /// <param name="maxWriteCount">写的最大数量,超出后,改变写入速度</param> /// <param name="handleMessageAction">处理消息的方法</param> /// <param name="handNoCountAction">当卡队列处理完毕的通知</param> public DoubleBufferQueue(int maxWriteCount, Action <T> handleMessageAction, Action handNoCountAction) { EnsureUtil.NotNull(handleMessageAction, "消息处理方法不能为空"); _writeQueue = new ConcurrentQueue <T>(); _readQueue = new ConcurrentQueue <T>(); _handleMessageAction = handleMessageAction; _handNoCountAction = handNoCountAction; _maxWriteCount = maxWriteCount; }