- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
MSDN 评论 http://msdn.microsoft.com/en-us/library/dd267312.aspx声明...
“BlockingCollection 的默认集合类型是 ConcurrentQueue”
这是否意味着当我在集合上运行“GetConsumingEnumerable()”时,提取的项目正在从队列中出列并且在使用后将被标记为 GC?
换句话说......在下面的片段中,
foreach (var item in collection.GetConsumingEnumerable())
{
//do something with item
}
循环迭代后 item 会发生什么?
最佳答案
这些项目将从集合中删除,如果不存在对它们的其他引用,它们将有资格被收集。
来自 GetConsumingEnumerable 的文档:
Return Value
Type:System.Collections.Generic.IEnumerable<T>
AnIEnumerable<T>
that removes and returns items from the collection.
(我的重点)
关于c# - GetConsumingEnumerable 实际上是否从 BlockingCollection 中删除了一个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17279828/
解决方案 1 和 2 之间的区别是什么,_taskQ 是 BlockingCollection,我正在尝试实现生产者-消费者场景。 BlockingCollection 使用默认的 Concurren
我有一个使用任务并行库的可量化和可重复的问题,BlockingCollection , ConcurrentQueue & GetConsumingEnumerable在尝试创建一个简单的管道时。 简
有人可以确认下面的代码确实从 BlockingCollection 中删除了项目 foreach (var item in myCollection.GetConsumingEnumerable())
MSDN 评论 http://msdn.microsoft.com/en-us/library/dd267312.aspx声明... “BlockingCollection 的默认集合类型是 Conc
我有一个进程生成工作,第二个进程带有 BlockingCollection<>那消耗了那份工作。当我关闭我的程序时,我需要我的消费者停止消费工作,但我仍然需要快速记录未决但尚未消费的工作。 现在,我的
在下面的代码中,我使用 CancellationToken 在生产者不生产时唤醒 GetConsumingEnumerable() 并且我想脱离 foreach 并退出任务。但我没有看到 IsCanc
我有多个生产者和多个消费者的情况。生产者将作业放入队列中。我选择了 BlockingCollection,它工作得很好,因为我需要消费者等待找到工作。但是,如果我使用 GetConsumingEnum
我正在使用 BlockingCollection 来实现任务调度程序,基本上: public class DedicatedThreadScheduler : TaskScheduler, IDisp
我正在尝试通过 WAN 对多个目标执行并行 SqlBulkCopy,其中许多目标可能连接速度较慢和/或连接中断;它们的连接速度从 2 到 50 兆位下载不等,我正在通过 1000 兆位上传的连接发送;
我已经对这两个循环进行了试验,并开始注意到,即使任务的 Action 委托(delegate)中的常规 foreach 循环应该并行执行,它也不会并行处理元素。但是,如果我用 Parallel.For
我是一名优秀的程序员,十分优秀!