ConcurrentQueue
.Net和.Net有什么区别BlockingCollection
?
BlockingCollection
当可以通过 完成时,为什么最适合生产者-消费者操作ConcurrentQueue
?我必须改进以下代码中的任何内容吗?
MessageSlotMachineGameStartOrAndStatusUpdate msg;
while (!aCancellationToken.IsCancellationRequested)
{
try
{
this.isStillConsumingMsg = true;
Boolean takeResult = this.msgQueue.TryTake(out msg, this.msgConsumeTimeOut, aCancellationToken);
if (takeResult)
{
if (msg != null)
{
this.ProcessMessage(msg);
}
}
else
{
break;
}
}
catch (OperationCanceledException err)
{
EngineManager.AddExceptionLog(err, "Signal Operation Canceled");
}
catch (Exception err)
{
EngineManager.AddExceptionLog(err, "Signal exception");
}
finally
{
this.isStillConsumingMsg = false;
}
}