Esempio n. 1
0
        /// <summary>
        /// 停止接受消息并清空队列
        /// </summary>
        public void Stop()
        {
            if (!IsRunning)
            {
                throw new Exception("invoker is not start");
            }

            IsRunning = false;
            CancelSource.Cancel();
            MsgSem.Release(InvokerCount);
            Task.WaitAll(InnerTasks);
            Clear();
        }
Esempio n. 2
0
        protected void TaskProc()
        {
            while (!CancelSource.IsCancellationRequested)
            {
                MsgSem.WaitOne();

                if (CancelSource.IsCancellationRequested)
                {
                    break;
                }

                T value = default(T);
                if (MsgQueue.TryDequeue(out value))
                {
                    InvokerAction?.Invoke(value);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 添加消息
 /// </summary>
 /// <param name="value">消息</param>
 public void Add(T value)
 {
     MsgQueue.Enqueue(value);
     MsgSem.Release();
 }