I am writing a dll which runs several threads reading from a Queue, the calling program calls EnqueueTask with a data object. If I use lock around the queue object nothing goes in the queue, if I comment the lock than it works well (but causes a problem with the threads)
Please help
Code:public class messagesQueue :IDisposable { EventWaitHandle waitHandle = new AutoResetEvent (false); Thread _workerThread; object locker = new object(); Queue<reportData> _messageQueue;// = new Queue<reportData>(); /// <summary> /// Constructor /// </summary> public messagesQueue() { _messageQueue = new Queue<reportData>(); } /// <summary> /// Add record to the queue /// </summary> /// <param name="reportDataObj"></param> public void EnqueueTask(reportData reportDataObj) { lock (locker) { _messageQueue.Enqueue(reportDataObj); } waitHandle.Set(); }




Reply With Quote