I have one thread which is adding data in the queue, now I want that other thread should get notified when the data is added so that it can start processing data from queue.
one option is thread will poll the queue continuously to see if count is more than zero but I think this is not good way, any other suggestion will be greatly appreciated
Any suggestion how I can achieve this, I am using .net framework 3.5.
and what if i have two thread one is doing q.Enqueue(data)
and other is doing q.dequeue()
, in this case do i need to manage the lock..?
You can use ManualResetEvent
to notify a thread.
ManualResetEvent e = new ManualResetEvent(false);
After each q.enqueue();
do e.Set()
and in the processing thread, you wait for items with e.WaitOne()
.
If you do processing inside a loop, you should do e.Reset()
right after e.WaitOne()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With