private void ConsumeAndPublish(LockedQueue <Message> @in, LockedQueue <Message> @out, string name) { int count = 0; Message msg; while (true) { var received = @in.TryDequeue(out msg); if (received) { count++; @out.Enqueue(msg); if (msg.Terminate) { break; } } } Console.WriteLine("Consumer {0} received {1:#,#;;0} messages.", name, count); }