Hi,
Thanks for your help.
I can safely replace 2003 C#
static System.Collecti ons.Queue myUnSynchronize dQueue=new
System.Collecti ons.Queue();
static System.Collecti ons.Queue
mySynchronizedQ ueue=System.Col lections.Queue. Synchronized(my UnSynchronizedQ ueue);
void f() {
lock(mySynchron izedQueue.SyncR oot)
{
IEnumerator myEnumerator=my SynchronizedQue ue.GetEnumerato r();
}
}
with 2005 C#
static System.Collecti ons.Generic.Que ue<myType>
mymSynchronized Queue=new System.Collecti ons.Generic.Que ue<myType>();
void f() {
lock(mySynchron izedQueue)
{
IEnumerator<myT ype>
myEnumerator=my SynchronizedQue ue.GetEnumerato r();
}
}
without any other code modifications (except removing unnecessary
type casts) while porting a working 2003 project?
Thanks,
Mark
On Wed, 15 Feb 2006 03:42:24 -0500, "William Stacey [MVP]"
<wi************ @gmail.com> wrote:
The Queue<T> is not thread safe.
"Public static (Shared in Visual Basic) members of this type are thread
safe. Any instance members are not guaranteed to be thread safe.
A Queue can support multiple readers concurrently, as long as the collection
is not modified. Even so, enumerating through a collection is intrinsically
not a thread-safe procedure. 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 ."
I would provide your own syncRoot and lock on that during instance method
calls.