title: ConcurrentQueue.Count extremely slow in .NET Core
body: <p>I'm using a <code>ConcurrentQueue</code> to enqueue items from an I/O bound task and dequeue them from another for processing. I stop adding items to the queue when it reaches a certain size, so the processing can catch up. To do this I check the <code>ConcurrentQueue.Count</code> property. </p>
  
  <p>The problem is that the <code>Count</code> property doesn't seem to behave as it does in a List or other collections. It's extremely slow, and the larger the queue the slower it takes to read the <code>Count</code> property. With 20k items in a <code>ConcurrentQueue</code> almost all processor time is spent on the <code>Count</code> property.</p>
  
  <p><strong>Rough Example:</strong></p>
  
  <pre><code>        while (reader.Read())
          {
              if(Queue.Count &gt;= MaxQueueSize)
              {
                  //Wait
              }
              //Do Stuff
          }
  </code></pre>
  
  <p>When running a performance profiler, all the time is spent on <code>System.Collections.Concurrent.CDSCollectionETWBCLProvicer.ctor()</code>.</p>
  
  <p>This only seems to occur on .NET Core 2, this does not occur in .NET 4.6.2</p>
  
  <p>Is there any way around this in .Net Core?</p>