From 3e7080d3b9c61eba244b2c2280f67ab5cf19a789 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Wed, 3 Feb 2021 01:15:10 -0800 Subject: [PATCH] Use consuming enumerator for queue processing This changes avoids us needing to write the proper error-checking code to see if a queue has been completed vs some unrelated failure. --- Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index 98f8301..d3b9fa5 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs @@ -222,10 +222,8 @@ namespace Hazel.Udp.FewerThreads } private void ProcessingLoop() { - while (this.isActive) + foreach (ReceiveMessageInfo msg in this.receiveQueue.GetConsumingEnumerable()) { - ReceiveMessageInfo msg = this.receiveQueue.Take(); - try { this.ReadCallback(msg.Message, msg.Sender, msg.ConnectionId); @@ -243,10 +241,8 @@ namespace Hazel.Udp.FewerThreads private void SendLoop() { - while (this.isActive) + foreach (SendMessageInfo msg in this.sendQueue.GetConsumingEnumerable()) { - SendMessageInfo msg = this.sendQueue.Take(); - try { if (this.socket.Poll(Timeout.Infinite, SelectMode.SelectWrite)) -- 2.39.5