By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Shared or not shared (vb.net)

P: n/a
I'm building a control with a property which values depend on the
current different files in a resourcefile.
Users that use my control can edit the property by selecting from a
dropdownlist which lists all the files in the resourcefile.
This list is being created in the constructor of my control.

Now i'm wondering ... whether i should make that list a private shared
member of the class, or just a private member.
My thought was that shared would be cool, so that on creation of
multiple of my control ... the list wouldn't have to be rebuilt
everytime...but...if after creating 1 of my control, the user adds a
file to the resourcefile... the control wouldn't be listing that newly
added file ...

Any idea how i can cleanly solve this issue?

thx

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <Y1*********************@hestia.telenet-ops.be>,
ju**@sotto.invalid says...
I'm building a control with a property which values depend on the
current different files in a resourcefile.
Users that use my control can edit the property by selecting from a
dropdownlist which lists all the files in the resourcefile.
This list is being created in the constructor of my control.

Now i'm wondering ... whether i should make that list a private shared
member of the class, or just a private member.
My thought was that shared would be cool, so that on creation of
multiple of my control ... the list wouldn't have to be rebuilt
everytime...but...if after creating 1 of my control, the user adds a
file to the resourcefile... the control wouldn't be listing that newly
added file ...

Any idea how i can cleanly solve this issue?


Shared (static) methods are useful when they need no instance data to
work with. They simply take one or more parameters, act on them and
return data -- nothing tied to an instance of the class.

It sounds like this list is being used by each instance of the control.
In that case, I would keep it an instance member.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2

P: n/a
If the list is the same between all instances of your control, then shared
would probably be appropriate.

To overcome the resource file changing, you could either use a
FileSystemWatcher and reload the shared list (which would allow all
instances to reflect the changes immediately), or allow some type of manual
(user-initiated) refresh.

"sotto" <ju**@sotto.invalid> wrote in message
news:Y1*********************@hestia.telenet-ops.be...
I'm building a control with a property which values depend on the
current different files in a resourcefile.
Users that use my control can edit the property by selecting from a
dropdownlist which lists all the files in the resourcefile.
This list is being created in the constructor of my control.

Now i'm wondering ... whether i should make that list a private shared
member of the class, or just a private member.
My thought was that shared would be cool, so that on creation of
multiple of my control ... the list wouldn't have to be rebuilt
everytime...but...if after creating 1 of my control, the user adds a
file to the resourcefile... the control wouldn't be listing that newly
added file ...

Any idea how i can cleanly solve this issue?

thx

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.