473,888 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread Safety for collections

How does dotnet handles thread safety of Collections ?

I derived some classes from CollectionBase and DictionaryBase, and created
some typed Add, Remove methods to call typeless based Add, Remove methods.
Do I have to handle the locking myself ?

If one thread gets the IEnumerator, and iterate it. What happens when
another thread wanna add things to the collection ?

Thanks
Jack
Nov 17 '05 #1
2 3233
I got it from MSDN. Only type operations are thread safe, and instance
operations are not thread safe. We have to synchronize the calls ourselves.

However, I've another question:
What's the differece between using Hashtable or implementing collections
based on DictionaryBase, in terms of performance and memory usage?
I need a collection class that can some itmes, say 10000 but should retrive
fast with its key.

"Jack" <jack@no_spam.c om> wrote in message
news:eR******** ******@TK2MSFTN GP15.phx.gbl...
How does dotnet handles thread safety of Collections ?

I derived some classes from CollectionBase and DictionaryBase, and created
some typed Add, Remove methods to call typeless based Add, Remove methods.
Do I have to handle the locking myself ?

If one thread gets the IEnumerator, and iterate it. What happens when
another thread wanna add things to the collection ?

Thanks
Jack

Nov 17 '05 #2
I got it from MSDN. Only type operations are thread safe, and instance
operations are not thread safe. We have to synchronize the calls ourselves.

However, I've another question:
What's the differece between using Hashtable or implementing collections
based on DictionaryBase, in terms of performance and memory usage?
I need a collection class that can some itmes, say 10000 but should retrive
fast with its key.

"Jack" <jack@no_spam.c om> wrote in message
news:eR******** ******@TK2MSFTN GP15.phx.gbl...
How does dotnet handles thread safety of Collections ?

I derived some classes from CollectionBase and DictionaryBase, and created
some typed Add, Remove methods to call typeless based Add, Remove methods.
Do I have to handle the locking myself ?

If one thread gets the IEnumerator, and iterate it. What happens when
another thread wanna add things to the collection ?

Thanks
Jack

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5238
by: David | last post by:
Hi guys I have in my application many collections (HashTable and ArrayList)loaded with configuration data, that means they are loaded at startup and then they are accessed only for read-only (items are only retrieved, never added, removed or replaced). To be thread-safe after startup do I need to made them Synchronized (and so slower), or are they thread safe in such case ? Thanks in advance
2
2284
by: Steve Jorgensen | last post by:
I frequently find myself wanting to use class abstraction in VB/VBA code, and frankly, with the tacked-on class support in VB/VBA, there are some problems with trying to do that and have any type-safety as well. I thought I would share some of what I've come to think about this after dealing with it several times of late. First, an example. Let's say I have several classes, each with a string property called Name, and I have several...
4
6664
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause potential problems for thread-safety. So far, I'm only confused. I need a proper explanation for the concept so I can understand how to write thread-safe functions in the future. My apologies for posting a long routine.
9
2110
by: Alexander Fleck | last post by:
Hi, I' ve to make a software module thread safe. I know how to realize that and what' re the main topics of thread safety. But I don' t know how thread safety can be tested. I read about a test for web servers. These apps' re tested with a stress test. That doesn' t work for my module. I searched the web but didn' t find a solution that satisfies me. I think that thread safety errors don' t occur reproduceable and so they' re hard to test and...
4
3349
by: Anders Borum | last post by:
Hello! I'm am currently working on making a central cache component threadsafe, and was looking at the synchronized implementation of the Hashtable. I was wondering why you'd really want to enforce thread safety in a remove method? Why would you care if two threads are trying to remove the same key from the hashtable? In the end, the key is removed (and that was probably what you were looking for).
0
274
by: Jack | last post by:
How does dotnet handles thread safety of Collections ? I derived some classes from CollectionBase and DictionaryBase, and created some typed Add, Remove methods to call typeless based Add, Remove methods. Do I have to handle the locking myself ? If one thread gets the IEnumerator, and iterate it. What happens when another thread wanna add things to the collection ? Thanks
4
2582
by: Warren Sirota | last post by:
Hi, I've got a method that I want to execute in a multithreaded environment (it's a specialized spider. I want to run a whole bunch of copies at low priority as a service). It works well running as a single application. I was wondering if there is a "Thread-Safety Analysis Wizard"? I'm sure I'm grossly off-base with the following, so I'm prepared to be embarrassed. Please point me in the right direction!
6
3151
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it to the client. Before adding data to the arraylist, I check if the depth of the arraylist is longer than iMaxQueueDepth, and if it is, I clear the arraylist. Is it possible that while I am clearing the arraylist, the ThreadMain at the same time...
7
2011
by: intrader | last post by:
I have the following small classes: //----------------code--------------- using System; using System.Collections.Generic; using System.Text; namespace ValidatorsLibrary { public class ValidatorBase {
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11186
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.