void test()
{
int count = 0;
// 临界资源区
var queue = new BlockingCollection<string>();
// 生产者线程
Task.Factory.StartNew(() =>
{
while (true)
{
queue.Add("value" + count);
count++;
}
});

// 消费者线程1
Task.Factory.StartNew(() =>
{
foreach (string value in queue.GetConsumingEnumerable())
{
Console.WriteLine("Worker 1: " + value);
}

});
// 消费者线程2
Task.Factory.StartNew(() =>
{
foreach (string value in queue.GetConsumingEnumerable())
{
Console.WriteLine("Worker 1: " + value);
}
});

Thread.Sleep(50000);
}

最新文章

  1. Spring Batch在大型企业中的最佳实践
  2. js保留两位小数
  3. 个人对final发布产品的排名
  4. WebApi 2:属性路由 [Route()],attribute routing
  5. python中使用xlrd、xlwt操作excel表格详解
  6. Swift - 实现点击cell动态修改高度
  7. Sass学习之路(1)——Sass简介
  8. implement Google&#39;s Open Source Slam &quot;Cartographer&quot; demos in ROS/rviz
  9. Learning Django Resources
  10. Import larger wordpress xml file
  11. Specified VM install not found: type Standard VM, name jdk1.6.0_05
  12. App根据第,HTML5流行?
  13. jQuery操作之效果
  14. 静态html制作之psd转html
  15. C# 通用单例窗体类
  16. gat和post封装代码
  17. [转]C#中基于GDI+(Graphics)图像处理系列之前言
  18. 用Flask+Redis维护Cookies池
  19. 总结几种清除浏览器的缓存,适用于明明已经修改bug,但是测试人员说问题还存在的情况下
  20. shiro设置session超时时间

热门文章

  1. 关于Spring的配置文件的注解使用
  2. 不在同一主机:vsftpd+pam+mysql
  3. UVa 11093 环形跑道(模拟)
  4. export与export default exports与module.exports的用法
  5. SQLServer创建用户、数据库、表、约束、存储过程、视图
  6. vysor 破解 (插件 V1.7.8 客户端2.1.0)
  7. m_Orchestrate learning system---三十二、数据库字段判断为空时容易出现问题,如何从根本上解决这个问题
  8. vsftpd配置手册(实用)
  9. 新概念 Lesson 2 Sorry, sir.
  10. 【转】Vue.js特点