/// <summary> /// 线程执行方法 /// </summary> private void DoWork() { while (IsThreadWorking || HasMessage()) { if (!_msgSemaphore.WaitOne(1)) { continue; } var msg = PickMessage(); OnPublishMessage.Invoke(msg); } }
public void AddMessage(string msg, bool direct) { if (direct) { OnPublishMessage.Invoke(msg); } else { lock (_msgQueue) { _msgQueue.Enqueue(msg); _msgSemaphore.Release(); } } }