Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 /// <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;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="fileInfo">文件信息</param>
 /// <param name="action">文件改变后的执行的方法</param>
 /// <param name="timeOutMillis">延迟时间</param>
 /// <param name="isStart">是否启动监听</param>
 public FileWatchUtil(FileInfo fileInfo, Action <FileStream> action, int?timeOutMillis = null, bool isStart = false)
 {
     if (timeOutMillis.HasValue)
     {
         _timeOutMillis = timeOutMillis.Value;
     }
     EnsureUtil.NotNull(action, "file changed action");
     EnsureUtil.NotNull(_fileInfo, "watching fileInfo");
     _fileChangedHandle = action;
     _fileInfo          = fileInfo;
     if (isStart)
     {
         OnWatchedFileChange(null);
         StartWatching();
     }
 }
Ejemplo n.º 4
0
        private Action <FileStream> _fileChangedHandle = null; //文件变动后执行方法

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="action">文件改变后的执行的方法</param>
        /// <param name="timeOutMillis">延迟时间</param>
        /// <param name="isStart">是否启动监听</param>
        public FileWatchUtil(string filePath, Action <FileStream> action, int?timeOutMillis = null, bool isStart = false)
        {
            if (FileUtil.IsExistsFile(filePath))
            {
                if (timeOutMillis.HasValue)
                {
                    _timeOutMillis = timeOutMillis.Value;
                }
                EnsureUtil.NotNull(action, "file changed action");
                _fileChangedHandle = action;
                _fileInfo          = new FileInfo(filePath);
                if (isStart)
                {
                    OnWatchedFileChange(null);
                    StartWatching();
                }
                _fileWatchList.Add(this);
            }
            else
            {
                //      LogUtil.Warn($"文件不存在【{filePath}】");
            }
        }