コード例 #1
0
        /// <summary>
        /// 启动刷新日志线程
        /// </summary>
        /// <param name="refreshCount">单次最大刷新日志条数</param>
        /// <param name="cacheCapcity">日志缓存容量,建议等于日志最大项数</param>
        public void StartRefreshLogThread(int refreshCount, int cacheCapcity)
        {
            if (refreshCount < 1)
            {
                throw new ArgumentException(string.Format("单次最大刷新日志条数参数值:{0}无效,该值不能小于1", refreshCount), "refreshCount");
            }

            if (cacheCapcity < refreshCount)
            {
                throw new ArgumentException(string.Format("日志缓存容量参数值:{0}无效,该值不能小于单次最大刷新日志条数参数值:{1}", cacheCapcity, refreshCount), "cacheCapcity");
            }

            lock (this._logShowQueueLock)
            {
                if (this._refreshCount == refreshCount && this._cacheCapcity == cacheCapcity)
                {
                    //参数相同,忽略
                    return;
                }

                if (this._logShowQueue != null)
                {
                    this._logShowQueue.Stop();
                    this._logShowQueue.Dispose();
                }

                this._logShowQueue = new AsynQueue <ShowLogItem>(this.ShowLog, refreshCount, 10, "日志显示线程", true, true, cacheCapcity);
            }
        }
コード例 #2
0
 /// <summary>
 /// 释放资源方法
 /// </summary>
 /// <param name="isDispose">是否释放标识</param>
 protected virtual void Dispose(bool isDispose)
 {
     if (this._asynPublishParaQueueThread != null)
     {
         this._asynPublishParaQueueThread.Dispose();
         this._asynPublishParaQueueThread = null;
     }
 }
コード例 #3
0
        private void FTestAsynParallelQueue_Load(object sender, EventArgs e)
        {
            if (this.DesignMode)
            {
                return;
            }

            this._apQueue      = new AsynParallelQueue <int, string>(Pro, ProResult, 4, 10, true);
            this._retShowQueue = new AsynQueue <List <string> >(this.ProShow, "结果显示线程", true, true);
            this._createThread = new ThreadEx(this.Create, "生产线程", true);
        }
コード例 #4
0
        private void FTestLMQCenter_Load(object sender, EventArgs e)
        {
            LMQConfigManager.AddLMQConfig(new LMQConfig(_topic)
            {
                ParallelPublish = true, SyncPublish = true
            });

            LMQCenter.Subscibe(new SubscibeItem(_topic, this.Rev));
            LMQCenter.Subscibe(new SubscibeItem(_topic, this.Rev2));

            this._pushQueue = new AsynQueue <string>(this.Push);
            this._pushQueue.Start();
        }
コード例 #5
0
        /// <summary>
        /// 启动刷新日志线程
        /// </summary>
        private void StartRefreshLogThread()
        {
            lock (this._logLock)
            {
                if (this._logShowQueue != null)
                {
                    this._logShowQueue.Stop();
                    this._logShowQueue.Dispose();
                    this._logShowQueue = null;
                }

                this._logShowQueue = new AsynQueue <ShowLogItem>(this.ShowLog, this._refreshCount, 10, "日志显示线程", true, true, this._cacheCapcity);
            }
        }
コード例 #6
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     try
     {
         lock (this._logLock)
         {
             if (this._logShowQueue != null)
             {
                 this._logShowQueue.Stop();
                 this._logShowQueue.Dispose();
                 this._logShowQueue = null;
             }
         }
     }
     catch (Exception ex)
     {
         Loger.Error(ex);
     }
 }
コード例 #7
0
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <param name="message">消息</param>
        public void Publish(object message)
        {
            LMQConfig config      = LMQConfigManager.GetLMQConfig(this.Topic);
            var       publishItem = new PublishItem(config, message);

            if (config != null && config.SyncPublish)
            {
                this.PublishThreadMethod(publishItem);
            }
            else
            {
                if (this._asynPublishParaQueueThread == null)
                {
                    string name = string.Format("本地消息队列主题{0}数据消息发布线程", this.Topic);
                    this._asynPublishParaQueueThread = new AsynQueue <PublishItem>(this.PublishThreadMethod, name, true, true);
                }

                this._asynPublishParaQueueThread.Enqueue(publishItem);
            }
        }
コード例 #8
0
ファイル: TransferNet.cs プロジェクト: windygu/UtilZ.DotnetEx
        /// <summary>
        /// 构造函数
        /// </summary>
        public TransferNet(TransferConfig config, IEnumerable <ushort> listenPorts, Action <ReceiveDataItem> rev)
        {
            if (listenPorts == null || listenPorts.Count() == 0)
            {
                throw new ArgumentNullException(nameof(listenPorts));
            }

            if (rev == null)
            {
                throw new ArgumentNullException(nameof(rev));
            }

            if (config == null)
            {
                config = new TransferConfig();
            }
            else
            {
                config.Validate();
            }

            this._revQueue = new AsynQueue <ReceiveDataItem>(rev, "TransferNet.接收数据输出线程", true, true);

            try
            {
                foreach (var listenPort in listenPorts)
                {
                    TransferConfig config2 = config.Clone();
                    config2.NetConfig.ListenEP = new IPEndPoint(IPAddress.Any, listenPort);
                    this._transferChannels.Add(new UdpTransferChannelItem(new TransferChannel(config2, this.TransferChannelRev)));
                }
            }
            catch (Exception)
            {
                this.Dispose();
                throw;
            }
        }
コード例 #9
0
        public TransferReceiver(TransferConfig config, ITransferNet net, Action <ReceiveDataItem> rev)
        {
            this._config = config;
            this._net    = net;
            this._rev    = rev;
            TransferParaManager.Init(config);

            this._revOutputQueue = new AsynQueue <ReceiveDataItem>(this.RevitemOutput, "拉收到数据输出线程", true, true);

            int threadCount = config.TransferThreadCount;

            this._reqDataThreads             = new ThreadEx[threadCount];
            this._reqDataThreadsEventHandles = new AutoResetEvent[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                this._reqDataThreadsEventHandles[i] = new AutoResetEvent(false);
                this._reqDataThreads[i]             = new ThreadEx(this.ReqDataThreadMethod, $"请求数据线程[{i}]", true);
                this._reqDataThreads[i].Start(this._reqDataThreadsEventHandles[i]);
            }

            this._revTimeoutCheckThread = new ThreadEx(this.RevTimeoutCheckThreadMethod, "接收超时检测线程", true);
            this._revTimeoutCheckThread.Start();
        }
コード例 #10
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     this._asynQueue = new AsynQueue <int>(this.QueueCallback, "异步队列线程", true, false);
 }