title: Using BlockingCollection<T>: OperationCanceledException, is there a better way?
body: <p>I'm making use of the (frankly great) <code>BlockingCollection&lt;T&gt;</code> type for a heavily multithreaded, high-performance app.</p>
  <p>There's a lot of throughput through the collection and on the micro-level it's highly performant.  However, for each 'batch' it will always be ended by flagging the cancellation token.  This results in an exception being thrown on any waiting <code>Take</code> call.  That's fine, but I would have settled for a return value or output parameter to signal it, because a) exceptions have an obvious overhead and b) when debugging, I don't want to manually turn off break-on-exception for that specific exception.</p>
  <p>The implementation seems intense, and in theory I suppose I could disassemble and recreate my own version that didn't use exceptions, but perhaps there's a less complex way?</p>
  <p>I could add a <code>null</code> (or if not, a placeholder) object to the collection to signify the process should end, however there also needs to be a means to abort nicely, i.e. wake up waiting threads and tell them somehow that something's gone on.</p>
  <p>So - alternative collection types?  Recreate my own?  Some way to abuse this one?</p>
  <p>(Some context: I went with <code>BlockingCollection&lt;T&gt;</code> because it has an advantage over manual locking around a <code>Queue</code>. As best I can tell the use of threading primitives is superb and in my case, a few milliseconds here-and-there and optimal core is use crucial.)</p>
  <p><strong>Edit:</strong> I've just opened a bounty for this one. I don't believe <a href="https://stackoverflow.com/a/9017473/11178549">Anastasiosyal's answer</a> covers the query I raise in my comment of it. I know this is a tough problem. Is anyone able to assist?</p>