namespace SampleCollection { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void producer_Click(object sender, EventArgs e) { int i = 0; while (i <= 10) { i++; ProducerConsumer obj = new ProducerConsumer(); ThreadPool.QueueUserWorkItem(obj.Producer, i); } } } public class ProducerConsumer { public static BlockingCollection<object> queue = new BlockingCollection<object>(); public static Thread producerThread = null; static ProducerConsumer() { producerThread = new Thread(new ThreadStart(Consumer)); producerThread.Start(); } public void Producer(object item) { queue.Add(item); } public static void Consumer() { while (true) { object item =queue.Take(); // Add my code to process the item here. } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)