Entwickler-Ecke

C# - Die Sprache - Queue.Synchonized für generische Queues ???


winx - Di 11.12.07 11:13
Titel: Queue.Synchonized für generische Queues ???
Hi,

ich möchte gernen meinen generischen Queue


C#-Quelltext
1:
Queue<ProcessItem> m_CamQueue = ...                    


per Synchronize thread-safe machen, bekomme das aber nich hin...

wie sieht denn da die Syntax aus, denn


C#-Quelltext
1:
m_MarkQueue = new Queue<ProcessItem>.Synchronize                    


gibt es nicht, wie bei Standardqueues:


C#-Quelltext
1:
Queue q = Queue.Synchronized(new Queue());                    


Dankeschön für den entscheidenden Hinweis :D

gruß,
winx


Kha - Di 11.12.07 11:18

Wenn die Queue das nicht von selbst kann, musst du wohl selbst für die Synchronisierung sorgen. Steht übrigens alles auch im SDK ;) ...
Zitat:
Default implementations of collections in System.Collections.Generic are not synchronized.

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.