Пример #1
0
        /// <summary>
        /// 线程执行方法
        /// </summary>
        private void DoWork()
        {
            while (IsThreadWorking || HasMessage())
            {
                if (!_msgSemaphore.WaitOne(1))
                {
                    continue;
                }

                var msg = PickMessage();
                OnPublishMessage.Invoke(msg);
            }
        }
Пример #2
0
 public void AddMessage(string msg, bool direct)
 {
     if (direct)
     {
         OnPublishMessage.Invoke(msg);
     }
     else
     {
         lock (_msgQueue)
         {
             _msgQueue.Enqueue(msg);
             _msgSemaphore.Release();
         }
     }
 }