473,769 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Collections and ICollection.Syn cRoot

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 UserGroupPermis sionCollection:

Public Class UserGroupPermis sionCollection
Inherits System.Collecti ons.CollectionB ase

Private _userGroupIdHas htable As New Hashtable

Public ReadOnly Property UserGroupIdHash table() As Hashtable
Get
Return _userGroupIdHas htable
End Get
End Property

Public Sub Add(ByVal newUserGroupFun ctions As
UserGroupFuncti onCollection)
Me.List.Add(new UserGroupFuncti ons)
UserGroupIdHash table.Add(newUs erGroupFunction s.Id,
newUserGroupFun ctions)
End Sub

Public Sub Remove(ByVal removeUserGroup Functions As
UserGroupFuncti onCollection)
Me.List.Remove( removeUserGroup Functions)
UserGroupIdHash table.Remove(re moveUserGroupFu nctions.Id)
End Sub

Default Public ReadOnly Property Item(ByVal userGroupId As Int32)
As UserGroupFuncti onCollection
Get
Return UserGroupIdHash table.Item(user GroupId)
End Get
End Property

Public Shadows Sub Clear()
MyBase.Clear()
UserGroupIdHash table.Clear()
End Sub

End Class

This is the declaration and property in the module:

Private _userGroupPermi ssions As New UserGroupPermis sionCollection

Public ReadOnly Property UserGroupPermis sions() As
UserGroupPermis sionCollection
Get
Return _userGroupPermi ssions
End Get
End Property
This is my code in the aspx page:

Dim _newUserGroupFu nctions As New UserGroupFuncti onCollection
Dim userGroupFuncti on As UserGroupFuncti on

....Do some stuff and set values in the userGroupFuncti on Structure and
Add them to the _newUserGroupFu nctions Collection

Dim _userGroupPermi ssions As System.Collecti ons.ICollection =
UserGroupPermis sions

SyncLock _userGroupPermi ssions.SyncRoot
'Get current function collection to be removed
Dim _removeUserGrou pFunctions As UserGroupFuncti onCollection = _
UserGroupPermis sions(iUserGrou pId)

If Not _removeUserGrou pFunctions Is Nothing Then
'Remove collection
UserGroupPermis sions.Remove(_r emoveUserGroupF unctions)
End If

UserGroupPermis sions.Add(_newU serGroupFunctio ns) 'Add new
collection
End SyncLock

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

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

Similar topics

1
1644
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) equivalent business object(s). I have a custom collection that implements ICollection and IEnumerable. Here is the collection: Imports ERP.BusinessObjects Imports ERP.BusinessObjects.Helpdesk Imports ICTObjects.Collections
2
2102
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 = (Hashtable)collection.SyncRoot;
2
2894
by: Howard Swope | last post by:
Could someone help explain thread safety issues in the System.Collections classes? The documentation states: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Thread Safety Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. A SortedList can support multiple readers concurrently,...
0
254
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 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...
4
2224
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 the old code allowed me to do what basically was the following assignment: class SomeClass { private Queue q; SomeClass(Queue q)
5
2921
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 an "AppleBasket" which is a class that contains a collection of apples. So, some code: class Fruit{ }
4
3994
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 can raise an event and I need the managing class (Devices) to be able to catch these events. Public Class Device Public Event StatusChange()
5
4190
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 want to pass nested collections generically:
2
2644
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 System.Collections.Generic.ICollection< FeedImage> imagea ; FeedImage fee = new FeedImage ("http://www.image.com/image.jpg", "http://www.image.com");
0
9590
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
9424
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
10223
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...
1
10000
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
9866
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
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.