Shared or not shared (vb.net)

  • Thread starter Thread starter sotto
  • Start date Start date
S

sotto

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
 
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.
 
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.
 
Back
Top