예제 #1
0
 protected override void Dispose(bool disposing)
 {
     if(disposing)
     {
         if(processor != null) processor.Dispose();
         if(server != null) ((IDisposable) server).Dispose();
     }
     processor = null;
     factory = null;
     server = null;
     base.Dispose(disposing);
 }
예제 #2
0
 public void Dispose()
 {
     messageProcessor.Dispose();
 }
예제 #3
0
 public void Dispose()
 {
     _messageProcessor.Dispose();
     _envelopeReceiver.Dispose();
 }
예제 #4
0
        /// <summary>
        /// 停止全部任务
        /// </summary>
        /// <returns></returns>
        public static void Stop()
        {
            Logger.Info("MessageWorkBench 停止......");
            try
            {
                //停止标识
                _cts.Cancel();


                if (null != _LstProcessors)
                {
                    ///停止消费;迭代堆栈 从里面建处理器停止并注销
                    while (!_LstProcessors.IsEmpty)
                    {
                        try
                        {
                            IMessageProcessor procesorItem = null;
                            _LstProcessors.TryDequeue(out procesorItem);
                            if (null != procesorItem)
                            {
                                procesorItem.Stop();
                                procesorItem.Dispose();//释放处理器对象
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                    }

                    //停止线程
                    //------------停止采集线程-------------
                    while (!_TheadQueuePool_FetchMessage.IsEmpty)
                    {
                        Thread th = null;
                        _TheadQueuePool_FetchMessage.TryDequeue(out th);
                        //if (null != th && th.ThreadState != ThreadState.Stopped)
                        //{
                        //    try
                        //    {
                        //       // th.Abort();------注意:.net core 不支持 Abort方法
                        //      System.Threading.Thread.su
                        //    }
                        //    catch { }
                        //}
                    }

                    //----------停止处理消息线程---------------
                    while (!_TheadQueuePool_Processor.IsEmpty)
                    {
                        Thread th = null;
                        _TheadQueuePool_Processor.TryDequeue(out th);
                    }



                    //var enumtor_processor = _TheadQueuePool_Processor.GetEnumerator();
                    //while (enumtor_processor.MoveNext())
                    //{
                    //    var th = enumtor_processor.Current;
                    //    //if (null != th && th.ThreadState != ThreadState.Stopped)
                    //    //{
                    //    //    try
                    //    //    {
                    //    //        th.Abort();
                    //    //    }
                    //    //    catch { }

                    //    //}
                    //}
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            finally
            {
                _cts.Dispose();
            }
        }