为什么我的ReactiveExtensions msmq包装器不能继续监听?

时间:2017-05-31 19:00:44

标签: c# system.reactive msmq

任何人都可以确定为什么一次收听MSMQ,然后退出?我认为DoWhile()会让它保持监听,但是当启动时队列中有消息时,它会处理它们一次然后退出。在StopRequested之前是否有更合适的倾听方式?

public virtual void RunProcessor()
{
    _stopRequested = false;
    MessageQueue mq = null;
    try
    {
        //create a subscribable stream from the msmq async BeginRecieve event
        mq = GetMessageQueue();
        var msmqListener =
            Observable.FromAsync(() => Task<Message>.Factory.FromAsync(mq.BeginReceive(), mq.EndReceive));
        Subscribe(msmqListener.DoWhile(() => !StopRequested));
    }
    catch (Exception ex)
    {
        if ((ex is ThreadAbortException) || (ex is ThreadInterruptedException)) throw;
        _logger.Error("Alert processor thread threw an exception", ex);
    }
    finally
    {
        mq?.Close();
    }
}

0 个答案:

没有答案