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

Use of shared class members in ASP.NET

P: n/a
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object in
that shared member function the system maintains a local copy of that object
per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If I
have a shared member which declares a variable a of type Integer. the actual
storage of this integer I assume would be on the users one thread and cannot
be confused with anyone slses (UNLESS) the variable is static as pointed out
by Jay.

The reason this is making me paranoid is that I want to make extensive used
of shared functions in my data layer to reduce code bloat and constant
instantiation.

Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the dataset
would be overwritten, I cant see how this can be right. I decided to re-do
this posting thread to start afresh, I hope no one minds.

Sorry for being a little paranoid here, but i dont want to embark upon loads
of work and then find out Im screwed!

--
Best Regards

The Inimitable Mr Newbie
Dec 4 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object
in that shared member function the system maintains a local copy of that
object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If I
have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one thread
and cannot be confused with anyone slses (UNLESS) the variable is static
as pointed out by Jay.


Local variables are allocated on the stack, which is memory that belongs
exclusively to the current thread.
David
Dec 4 '05 #2

P: n/a
That answers my question precisley.

Thank you

--
Best Regards

The Inimitable Mr Newbie
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:ei****************@TK2MSFTNGP12.phx.gbl...

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object
in that shared member function the system maintains a local copy of that
object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If I
have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one thread
and cannot be confused with anyone slses (UNLESS) the variable is static
as pointed out by Jay.


Local variables are allocated on the stack, which is memory that belongs
exclusively to the current thread.
David

Dec 4 '05 #3

P: n/a
I'm a little confused by your use of the word "shared," and in the same
message, "static." In VB.Net, "shared" means "static." So, are you referring
to "shared" as in "static," or for some other meaning? If not "static," what
definition of "shared" are you meaning?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object
in that shared member function the system maintains a local copy of that
object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If I
have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one thread
and cannot be confused with anyone slses (UNLESS) the variable is static
as pointed out by Jay.

The reason this is making me paranoid is that I want to make extensive
used of shared functions in my data layer to reduce code bloat and
constant instantiation.

Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the dataset
would be overwritten, I cant see how this can be right. I decided to re-do
this posting thread to start afresh, I hope no one minds.

Sorry for being a little paranoid here, but i dont want to embark upon
loads of work and then find out Im screwed!

--
Best Regards

The Inimitable Mr Newbie

Dec 4 '05 #4

P: n/a
Mr, Newbie,
Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the dataset
would be overwritten, I cant see how this can be right.


If you had asked that original thread than I would have explained in another
way for you. As far as I know was you not the OP, if you was the OP, than
please don't confuse us.

Especially do I not understand why you send messages to the framework.aspnet
group, where in you suggest that I give wrong answers in the language.vb
newsgroup, without telling in one word what the question was.

If you are sure that my answer is wrong, than you can start a discussion or
ignore it, however telling it in other newsgroups is for me undecent.

Cor

Dec 4 '05 #5

P: n/a
Sorry, yes I meant the same thing, its an occupational hazard of switching
languages.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e3***************@TK2MSFTNGP11.phx.gbl...
I'm a little confused by your use of the word "shared," and in the same
message, "static." In VB.Net, "shared" means "static." So, are you
referring to "shared" as in "static," or for some other meaning? If not
"static," what definition of "shared" are you meaning?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object
in that shared member function the system maintains a local copy of that
object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If I
have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one thread
and cannot be confused with anyone slses (UNLESS) the variable is static
as pointed out by Jay.

The reason this is making me paranoid is that I want to make extensive
used of shared functions in my data layer to reduce code bloat and
constant instantiation.

Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the
dataset would be overwritten, I cant see how this can be right. I decided
to re-do this posting thread to start afresh, I hope no one minds.

Sorry for being a little paranoid here, but i dont want to embark upon
loads of work and then find out Im screwed!

--
Best Regards

The Inimitable Mr Newbie


Dec 4 '05 #6

P: n/a
Im very sorry. I did not mean to upset you in any way.

I simply became confused with the answers, I should have replied on the
original thread. My appologies.
-
Best Regards

The Inimitable Mr Newbie
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Mr, Newbie,
Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the
dataset would be overwritten, I cant see how this can be right.


If you had asked that original thread than I would have explained in
another way for you. As far as I know was you not the OP, if you was the
OP, than please don't confuse us.

Especially do I not understand why you send messages to the
framework.aspnet group, where in you suggest that I give wrong answers in
the language.vb newsgroup, without telling in one word what the question
was.

If you are sure that my answer is wrong, than you can start a discussion
or ignore it, however telling it in other newsgroups is for me undecent.

Cor

Dec 4 '05 #7

P: n/a
Hi Mr. N,

Static data is singleton data. That is, there is one copy for the entire
application. There is not one copy per thread.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Sorry, yes I meant the same thing, its an occupational hazard of switching
languages.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e3***************@TK2MSFTNGP11.phx.gbl...
I'm a little confused by your use of the word "shared," and in the same
message, "static." In VB.Net, "shared" means "static." So, are you
referring to "shared" as in "static," or for some other meaning? If not
"static," what definition of "shared" are you meaning?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about a
couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local object
in that shared member function the system maintains a local copy of that
object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If
I have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one thread
and cannot be confused with anyone slses (UNLESS) the variable is static
as pointed out by Jay.

The reason this is making me paranoid is that I want to make extensive
used of shared functions in my data layer to reduce code bloat and
constant instantiation.

Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the
dataset would be overwritten, I cant see how this can be right. I
decided to re-do this posting thread to start afresh, I hope no one
minds.

Sorry for being a little paranoid here, but i dont want to embark upon
loads of work and then find out Im screwed!

--
Best Regards

The Inimitable Mr Newbie



Dec 4 '05 #8

P: n/a
Yes, I realise that. My concerns were over non static variables, I was
concerned that there may be scope for overwriting in a multi user
environment, but this was unfounded.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ue***************@TK2MSFTNGP12.phx.gbl...
Hi Mr. N,

Static data is singleton data. That is, there is one copy for the entire
application. There is not one copy per thread.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Sorry, yes I meant the same thing, its an occupational hazard of
switching languages.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e3***************@TK2MSFTNGP11.phx.gbl...
I'm a little confused by your use of the word "shared," and in the same
message, "static." In VB.Net, "shared" means "static." So, are you
referring to "shared" as in "static," or for some other meaning? If not
"static," what definition of "shared" are you meaning?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
I'm still thinking around this subject, and I find myself unsure about
a couple of things.

When a new users launches an ASP.NET application, this must be on a new
thread. When it encounters a shared member in a class, unless you are
setting static variables presumably when you instantiate an local
object in that shared member function the system maintains a local copy
of that object per thread ( is this right ? ).

To perhaps make my point more clearly. In a shared member function, If
I have a shared member which declares a variable a of type Integer. the
actual storage of this integer I assume would be on the users one
thread and cannot be confused with anyone slses (UNLESS) the variable
is static as pointed out by Jay.

The reason this is making me paranoid is that I want to make extensive
used of shared functions in my data layer to reduce code bloat and
constant instantiation.

Does anyone see any issues with this. Cor's example in the earlier post
related to a dataset does not seem right to me as he says that the
dataset would be overwritten, I cant see how this can be right. I
decided to re-do this posting thread to start afresh, I hope no one
minds.

Sorry for being a little paranoid here, but i dont want to embark upon
loads of work and then find out Im screwed!

--
Best Regards

The Inimitable Mr Newbie



Dec 4 '05 #9

P: n/a
Mr. Newbie,

I simply became confused with the answers, I should have replied on the
original thread. My appologies.


Let me accept it and therefore repeat, a webapplication (is a DLL not an
Exe), is a middle tier application.

It's sharing its shared parts (even its static parts) for all users.

Therefore if you create this construction (which can be done in winforms).
\\\
Public Shared ds as dataset
Public shared sub fillmydataset(byval clientnumber as string)
dim sqlstring as string = "Select from table where client = '" &
clientnumber & "'"
' in a lazy way of coding without parameters
'rest of the code
da.fill(ds)
end sub
///

Than every time that a client does a "fillmydataset", the shared member ds
of the application will be overwritten. You have than therefore in my
opinion not any control about it when this will happen and cannot use that
dataset in your updates even not if you read it very quick in advance.

I hope that this gives an idea

Cor
Dec 5 '05 #10

P: n/a
Thanks for your help.

--
Best Regards

The Inimitable Mr Newbie
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Mr. Newbie,

I simply became confused with the answers, I should have replied on the
original thread. My appologies.


Let me accept it and therefore repeat, a webapplication (is a DLL not an
Exe), is a middle tier application.

It's sharing its shared parts (even its static parts) for all users.

Therefore if you create this construction (which can be done in winforms).
\\\
Public Shared ds as dataset
Public shared sub fillmydataset(byval clientnumber as string)
dim sqlstring as string = "Select from table where client = '" &
clientnumber & "'"
' in a lazy way of coding without parameters
'rest of the code
da.fill(ds)
end sub
///

Than every time that a client does a "fillmydataset", the shared member
ds of the application will be overwritten. You have than therefore in my
opinion not any control about it when this will happen and cannot use that
dataset in your updates even not if you read it very quick in advance.

I hope that this gives an idea

Cor

Dec 5 '05 #11

P: n/a
Ah, I misunderstood.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:u5***************@TK2MSFTNGP12.phx.gbl...
Yes, I realise that. My concerns were over non static variables, I was
concerned that there may be scope for overwriting in a multi user
environment, but this was unfounded.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ue***************@TK2MSFTNGP12.phx.gbl...
Hi Mr. N,

Static data is singleton data. That is, there is one copy for the entire
application. There is not one copy per thread.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Sorry, yes I meant the same thing, its an occupational hazard of
switching languages.

--
Best Regards

The Inimitable Mr Newbie
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e3***************@TK2MSFTNGP11.phx.gbl...
I'm a little confused by your use of the word "shared," and in the same
message, "static." In VB.Net, "shared" means "static." So, are you
referring to "shared" as in "static," or for some other meaning? If not
"static," what definition of "shared" are you meaning?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Mr Newbie" <he**@now.com> wrote in message
news:eE***************@TK2MSFTNGP09.phx.gbl...
> I'm still thinking around this subject, and I find myself unsure about
> a couple of things.
>
> When a new users launches an ASP.NET application, this must be on a
> new thread. When it encounters a shared member in a class, unless you
> are setting static variables presumably when you instantiate an local
> object in that shared member function the system maintains a local
> copy of that object per thread ( is this right ? ).
>
> To perhaps make my point more clearly. In a shared member function,
> If I have a shared member which declares a variable a of type Integer.
> the actual storage of this integer I assume would be on the users one
> thread and cannot be confused with anyone slses (UNLESS) the variable
> is static as pointed out by Jay.
>
> The reason this is making me paranoid is that I want to make extensive
> used of shared functions in my data layer to reduce code bloat and
> constant instantiation.
>
> Does anyone see any issues with this. Cor's example in the earlier
> post related to a dataset does not seem right to me as he says that
> the dataset would be overwritten, I cant see how this can be right. I
> decided to re-do this posting thread to start afresh, I hope no one
> minds.
>
> Sorry for being a little paranoid here, but i dont want to embark upon
> loads of work and then find out Im screwed!
>
>
>
> --
> Best Regards
>
> The Inimitable Mr Newbie
>



Dec 5 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.