MultiThreading in Queue
how to work on queue enqueue & dequeue process sysmultaneously in different thread in C#.NET
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 16, 2011, 10:36 AM EDT
Only reading the queue (i.e. the Peek method) is threadsafe and even then you have to ensure the Queue is not modified in the meantime.
Pankaj Gogoi31 reputationPosted Jun 16, 2011, 11:58 PM EDT
An instance member is not guaranteed to be thread safe. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization
You refer this link
http://msdn.microsoft.com/en-us/magazine/ee412257.aspx
You can try the ConcurrentQueue(Of T). Here is a link
http://msdn.microsoft.com/en-us/library/dd267265.aspx
Hope this helps
Thank you