Windows Develop Bookmark and Share   
 index > Windows Forms General > making Que threadsafe
 

making Que threadsafe

I have 2 separated thread that access one System.Collections.Queue object.

One thread runs PushToQueue() that does Que.Enqueue(SomeString)
and the second thread runs PullFromQueue() that does Que.Dequeue.

My question is that how can I make acces to Que threadsafe ??
MigrationUser 1  Friday, June 24, 2005 7:02 PM
Instead of instantiating the queue with
Queue queue = new Queue();
write:
Queue queue = Queue.Synchronized(new Queue());

Most of the framework's collections classes have this Synchronized method. Be sure to read the help for Synchronized, because iterating over a synchronized queue will fail if another thread changes the queue.
MigrationUser 1  Monday, June 27, 2005 5:28 AM

You can use google to search for other answers

Custom Search

More Threads

• Controls Resizing
• showing different text in a pannel at runtime
• DataTable Merge Problem
• Add a user Control and insert line of code
• OpenIcon
• invalid operation exception
• checkbox problem
• Checkbox like radio button
• Win Form changes/Save question
• I set DrawMode as OwnerDrawFixed, but can't get the horizontal scroll bar any more. (ListBox)