473,795 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deterministic Collection Using Generics

Here is my try at generics. This creates a collection that implements
IInvoke and IDisposable and Adds types that implement IInvoke and
IDisposable. When the collection goes out of using scope dispose is
called on all members of the collection. Calling Invoke on the
collection calls Invoke on each member of the collection.

http://www.geocities.com/jeff_louie/oop29.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Dec 17 '05 #1
3 1187
Jeff,

It appears the JALGenericColle ction<T> and JALCollection objects were
intended to be thread-safe, but they're not quite there yet. The
problem is with the Dispose method and the checks at the beginning of
Add, Clear, and Invoke to see if the object has been disposed.
Synchronization has not be applied correctly to prevent one thread from
calling Dispose while another calls Invoke after the object has been
disposed.

Aren't generics a great addition to the language?

Brian

Jeff Louie wrote:
Here is my try at generics. This creates a collection that implements
IInvoke and IDisposable and Adds types that implement IInvoke and
IDisposable. When the collection goes out of using scope dispose is
called on all members of the collection. Calling Invoke on the
collection calls Invoke on each member of the collection.

http://www.geocities.com/jeff_louie/oop29.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***


Dec 17 '05 #2
Brian...Thanks for the tip. My old brain is having trouble learning
thread safety. I moved the disposed clause inside the locks. Does this
look correct now?

http://www.geocities.com/jeff_louie/oop29.htm

You may need to refresh the page load. And yes, Generics are cool.

Regards,
Jeff
It appears the JALGenericColle ction<T> and JALCollection objects were

intended to be thread-safe, but they're not quite there yet. The problem
is with the Dispose method and the checks at the beginning of Add,
Clear, and Invoke to see if the object has been disposed.
Synchronization has not be applied correctly to prevent one thread from
calling Dispose while another calls Invoke after the object has been
disposed.

Aren't generics a great addition to the language?<
*** Sent via Developersdex http://www.developersdex.com ***
Dec 18 '05 #3

Jeff Louie wrote:
Brian...Thanks for the tip. My old brain is having trouble learning
thread safety. I moved the disposed clause inside the locks. Does this
look correct now?

http://www.geocities.com/jeff_louie/oop29.htm


It looks correct now. Thread-safety is tricky to get right.

Brian

Dec 18 '05 #4

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

Similar topics

6
4841
by: Michael D. Ober | last post by:
In VB 6, the loop iterator v in the following code must be a variant. dim v as variant dim c as new collection for each v in collection ... next v What is the general translation in VB 7.1 and VB 8 Beta 1? Also, is there an easy way to force "v" to be an early bound variable. In VB 6 this can be
3
1353
by: Michael Fällgreen | last post by:
Hi, I need to make a strongly typed collection of x, and the simplets way is to inherits list(of x). With that I can bind to a list-control. However - i don't need all the methods from list(of x). If I make a private list as list(of x) in a class and implements IList(of x) I can control what methods to be public. I works - but now I can't bind the collection to a listbox og grid (it says something about complex datatype).
8
1834
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; namespace DeterminedGenericCollection { // I got tired of copy and pasting IDisposable
4
3461
by: _DS | last post by:
I need to create arrays of a custom data type (which is composed of various strings, ints, the usual). The original was built using CollectionBase. I was thinking about redesigning to use generics, but I realized that DataSets may also work here. I do need to display and edit lists of the items at various places. In the previous version I used a custom ListView for most display purposes. Given that DataSets in VS2005 have so many...
4
1761
by: Robert Schneider | last post by:
Hi, the msdn documentation provides an Dinosaurs example that uses the objectmodel.collection class. Just have a look on the help page for this class. I don't understand what happens here. Or I cannot find more detailed documentation for this behavior. What I mean is the invocation of the Dinosaurs.Add method which is derived from Collection(of String). The method seems to invoke the overridden InsertItem method. Can this method be...
14
1711
by: cwineman | last post by:
Hello, I'm hoping to do something using Generics, but I'm not sure it's possible. Let's say I want to have a bunch of business objects and a data access class cooresponding to each business object. For each business object, I would have something like below: public class Apple { //apple stuff
7
5523
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the default behavior and then create an overload as IndexOf(int index, ProductSearchCriteria criteria)...
8
1557
by: Mike P | last post by:
I'm pretty new to OOP and I'm just starting looking at generics and collection classes. I understand why I might want to create a business class, but can somebody please explain to me the reasons behind creating collection classes? Many thanks, Mike
7
5749
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can iterate through the collection and use "foreach" on the collection. public class Cars : System.Collections.ObjectModel.Collection<Car{ } So, could someone explain to me why you would want to create a GENERIC custom collection class.
0
9519
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
10438
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
10214
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
10164
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
9042
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...
0
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.