473,320 Members | 1,887 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,320 software developers and data experts.

Collections and ICollection.SyncRoot

I am using collections in my project and have come up against some
issues. My project is a web based thin client application.

The main issue I have is with collections, I have all the users
settings/permissions etc held in a collection which is in a module.

This enables the user to access their settings from page to page
without quering a database every time the page loads.

Administrators of the system can change users settings while the user
is logged in. But, after reading up on collections that have multiple
readers/writers I discovered that I need to lock the collection before
the administrator can apply the changes, as there could be more than
one admin changing a setting.

I have read through MS documentation and have put together the code
below, which seems to be working, but I have no way of really knowing,
as the only test I can do is try editing the sam account at the same
time from various computers, which does seem to work.

Please can someone verify I have done this correctly?

Here is the UserGroupPermissionCollection:

Public Class UserGroupPermissionCollection
Inherits System.Collections.CollectionBase

Private _userGroupIdHashtable As New Hashtable

Public ReadOnly Property UserGroupIdHashtable() As Hashtable
Get
Return _userGroupIdHashtable
End Get
End Property

Public Sub Add(ByVal newUserGroupFunctions As
UserGroupFunctionCollection)
Me.List.Add(newUserGroupFunctions)
UserGroupIdHashtable.Add(newUserGroupFunctions.Id,
newUserGroupFunctions)
End Sub

Public Sub Remove(ByVal removeUserGroupFunctions As
UserGroupFunctionCollection)
Me.List.Remove(removeUserGroupFunctions)
UserGroupIdHashtable.Remove(removeUserGroupFunctio ns.Id)
End Sub

Default Public ReadOnly Property Item(ByVal userGroupId As Int32)
As UserGroupFunctionCollection
Get
Return UserGroupIdHashtable.Item(userGroupId)
End Get
End Property

Public Shadows Sub Clear()
MyBase.Clear()
UserGroupIdHashtable.Clear()
End Sub

End Class

This is the declaration and property in the module:

Private _userGroupPermissions As New UserGroupPermissionCollection

Public ReadOnly Property UserGroupPermissions() As
UserGroupPermissionCollection
Get
Return _userGroupPermissions
End Get
End Property
This is my code in the aspx page:

Dim _newUserGroupFunctions As New UserGroupFunctionCollection
Dim userGroupFunction As UserGroupFunction

....Do some stuff and set values in the userGroupFunction Structure and
Add them to the _newUserGroupFunctions Collection

Dim _userGroupPermissions As System.Collections.ICollection =
UserGroupPermissions

SyncLock _userGroupPermissions.SyncRoot
'Get current function collection to be removed
Dim _removeUserGroupFunctions As UserGroupFunctionCollection = _
UserGroupPermissions(iUserGroupId)

If Not _removeUserGroupFunctions Is Nothing Then
'Remove collection
UserGroupPermissions.Remove(_removeUserGroupFuncti ons)
End If

UserGroupPermissions.Add(_newUserGroupFunctions) 'Add new
collection
End SyncLock

Is this right or have I totaly missunderstood the whole concepted?
Jul 21 '05 #1
0 1322

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

Similar topics

1
by: womber | last post by:
I am getting XML from a dataset that has been populated via a storedprocedure no schemas have been applied nor any relationships. But the correct table names have been given to match the table(s)...
2
by: Nick | last post by:
Out of context and just asking but why does the following code work? Hashtable ht = new Hashtable(); ht.Add(1,1); .... .... ..... ICollection collection = ht.Values; Hashtable ht2 =...
2
by: Howard Swope | last post by:
Could someone help explain thread safety issues in the System.Collections classes? The documentation states:...
0
by: Gavin | last post by:
I am using collections in my project and have come up against some issues. My project is a web based thin client application. The main issue I have is with collections, I have all the users...
4
by: Adam Clauss | last post by:
I ran into a problem a while back when attempting to convert existing .NET 1.1 based code to .NET 2.0 using Generic collections rather than Hashtable, ArrayList, etc. I ran into an issue because...
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
4
by: Sid Price | last post by:
Hello, I have a class of objects (Device) that are managed by another object (Devices) with a collection class (DeviceCollection) inherited from Collections.Hashtable. Each of the Device objects...
5
by: Michi Henning | last post by:
I can pass a generic collection as ICollection<Tjust fine: static void flatCollection(ICollection<intc) {} // ... List<intl = new List<int>(); flatCollection(l); // Works fine Now I...
2
by: confused1234 | last post by:
Hi i'm trying to pass a field of type System.Collections.Generic.ICollection< FeedImage> to a function. I dont't have a clue what this icollection is. but i tried some code ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.