Scope of Shared Properties

  • Thread starter Thread starter daokfella
  • Start date Start date
D

daokfella

Quick question:

If my page instantiates a class that has a protected shared property,
is that property shared across all instances of the class...even those
that I didn't instantiate, but another user accessing the page did?

Thanks!
 
From my understanding of the shared descriptor in VB (I use C# mostly so I
may be a bit off), the shared property is never truly instantiated, it's
available directly whether the class is instantiated or not. Shared/static
members and properties should be able to be called without the class ever
being created. So yes, all the users who access this property should have
exactly the same value, which could lead to some very interesting results if
they are trying to write to it at the same time. An example of a shared
property for a class may be something like total number of users in a
membership system. All accounts will see the same total. Anytime a new
account is added and the shared property is incremented, all should see the
increment, but some locking should definitely be done when modifying this
value.
 
Back
Top