Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Don't take an InvalidOperationException as a sign you are done reading or writing. This will hide real bugs. And also don't Flush because it does make a (negative) difference. Commented Oct 13, 2012 at 13:30
  • @usr: You actually have to handle InvalidOperationException. Even if one checks IsCompleted, the task can be preempted and the blocking collection marked complete just after that check. Or am I missing something? Also, that is the pattern on MSDN (not that it makes it necessarily good. After all MSDN hardly ever disposes of IDisposable resources in their examples, etc.). Commented Oct 16, 2012 at 1:34
  • 1
    You could use BlockingCollection.GetConsumingEnumerable. In any cas,e I'd wrap the try-catch around just that line and make an effort to arrange everything so that only this Take call is protected. Commented Oct 16, 2012 at 10:41