473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Making a Collection Multithread safe

I need some help in trying to understand how to make myCollection (inherited
from CollectionBase) multithread safe.

Taking my implementation of the Add Sub and a readonly property Item.

Public Sub Add(ByVal aDoc As myDocument)
List.Add(aDoc)
End Sub

Can I make this multithread safe by and is this the best way to do it.

Public Sub Add(ByVal aDoc As myDocument)
Synclock myCollection.SyncRoot
List.Add(aDoc)
End Synclock
End Sub

I notice that the ArrayList Class has a Synchronized method. How would I
implement such a function for myCollection.
As for the Item property:

Default Public ReadOnly Property Item(ByVal index As Integer) As myDocument
Get
Return CType(List.Item(index), myDocument)
End Get
End Property

Am I correct in thinking that since it is readonly I do not need to make
this thread safe in order to protect myCollection?
If I do make it thread safe as per the Add Sub, then will it prevent
multiple access to the Item (myDocument) through the same instance of
myCollection? I realise that there may be many other ways of accessing the
Item.

Does using Synclock as per the Add Sub above have much affect on
performance?
Thanks
Fred
Nov 20 '05 #1
0 1295

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

Similar topics

1
by: Grandma Wilkerson | last post by:
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...
0
by: r_obert | last post by:
Hello, I'm trying to create a worker thread for my VC++ program, and was wondering whether I should be linking with the Multithread /MT or Multithread DLL /MD option? I'm not quite sure, in...
3
by: QQ | last post by:
I am new here and got lost on a multithread C++ system source codes Thanks a lot!
9
by: craig | last post by:
Assume that you would like to create a custom collection class that is: 1. Strongly-typed (only holds Customer objects) 2. Read-only (user cannot add Customer objects) 3. Able to be bound to...
23
by: Shalini Joshi | last post by:
Hi, I was trying to find out what exactly is meant by multi-thread safe code/functions etc. I couldn't find relevant information on the web and would appreciate any useful links/information on this...
6
by: Frank Rizzo | last post by:
ArrayList suffers from the same effect as the vb6 collection object. Once you add an object to the collection, you lose the intellisense for that object. Has anyone seen any wrappers for the...
11
by: Daniel Billingsley | last post by:
Let's say I'm writing a business app and I want there to be only one instance of the Customer object for each particular customer (representing a database record) being edited. Would it be...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
14
by: Jeff S. | last post by:
In a Windows Forms application I plan to have a collection of structs - each of which contains a bunch of properties describing a person (e.g., LastName, FirstName, EmployeeID, HomeAddress,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.