About Shared properties in ASP.NET

H

Henri

Hi,
I'm using a custom class in my ASP.NET which has a Shared property.
I don't want this Shared property to be shared between users because of
thread concurrent accesses problems.
I just want it to be shared between the several instances of the class
belonging to the same request/user.
I think I've read somewhere that shared properties are not shared among
users in ASP.NET. (that would be logic as a shared property should die after
each user's request has ended)
So I think I don't have to use SyncLock inside this Shared property as each
client request is run completely separately and a thread from a request
won't access the same shared property as another request's thread.
Am I right?
Thanks for your answer.
 
K

Kevin Spencer

I think I've read somewhere that shared properties are not shared among
users in ASP.NET. (that would be logic as a shared property should die
after
each user's request has ended)

Afraid not. Shared (static) objects are stored in the heap, and are
singletons (there is only one, no instance). The use of the syntax "shared"
is, IMHO, unfortunate, in that it is a little misleading. But what is
important is what it means. Instantiated objects are (copies of execution
code) placed on the stack, a volatile region of memory where instances are
placed while being used, and removed afterwards. Shared (static) objects
remain in the heap, a region of code into which the program execution code
is loaded (from the DLL) at startup.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top