What you described should work. There should be no reason why a collection
would have a problem with multiple threads iterating through it.
Ryan Byington [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
| From: "Grandma Wilkerson" <tu**@bottleneck.scalability.crash.dum>
| Subject: Thread-safe enumeration thru collection?
| Date: Thu, 17 Jul 2003 13:30:25 -0700
| Lines: 19
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <us**************@tk2msftngp13.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.general,microsoft.public.d otnet.languages.csharp
| NNTP-Posting-Host: rrcs-west-66-27-51-213.biz.rr.com 66.27.51.213
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:169990
microsoft.public.dotnet.general:101593
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Hi,
|
| The documentation states that enumeration through a collection is
| inherently NOT thread-safe, since a thread which added/removed an item
from
| said collection could screw up the thread that was iterating. That makes
| sense.. but... given a collection that is filled at start-time and never
| modified again, is it safe to have multiple threads *reading* (not writing
| to) the collection using foreach()?
|
| I have a class that exposes an event [which is really just a
collection
| of delegates]. The event registrants are all hooked up at startup. Is it
| safe for my class to fire the event simultaneously from two different
| threads even though this would lead to the delegate collection being
| iterated by two different threads?
|
|
|
|
|
|