Or offcourse [C#] public static Hashtable Synchronized( Hashtable table );
Remarks A Hashtable can support one writer and multiple readers concurrently. To support multiple writers, all operations must be done through this wrapper only. Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads. [Visual Basic, C#] The following code example shows how to lock the collection using the SyncRoot during the entire enumeration: [C#] Hashtable myCollection = new Hashtable(); lock( myCollection.SyncRoot ) { foreach ( Object item in myCollection ) { // Insert your code here. } } From: ms-help://MS.MSDNQTR.2004JUL.1033/cpref/html/frlrfSystemCollectionsHasht ableClassSynchronizedTopic.htm Paul -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Steve Johnson Sent: Wednesday, July 21, 2004 1:41 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Multithreaded hash table access James Berry wrote: > I'm sure there must be a really elegant way to do this. Any hints? Yep. Look at System.Threading.ReaderWriterLock. -- Steve Johnson =================================== This list is hosted by DevelopMentor(r) http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com