在ASP.NET中使用共享类成员 [英] Use of shared class members in ASP.NET

查看:68
本文介绍了在ASP.NET中使用共享类成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在考虑这个问题,我发现自己不确定是否有一些事情。


当新用户启动时ASP.NET应用程序,这必须是一个新的
线程。当遇到类中的共享成员时,除非你是设置静态变量,大概是当你在共享成员函数中实例化一个本地对象时系统维护一个本地副本那个对象
每个线程
(这是对的吗?)。


或许更清楚地说明我的观点。在共享成员函数中,如果我有一个共享成员,它声明一个Integer类型的变量a。这个整数的实际

存储我假设会在用户的一个线程上并且不能将b $ b与任何人相混淆(UNLESS)该变量是静态的指出

by Jay。


这让我变得偏执的原因是我想在我的数据中广泛使用

共享函数图层减少代码膨胀和常量

实例化。


有没有人看到任何问题。 Cor在早先的帖子

与数据集相关的例子对我来说似乎不对,因为他说数据集

会被覆盖,我不知道这是怎么回事可以是对的。我决定重新做这个帖子帖子重新开始,我希望没有人介意。


抱歉这里有点偏执,但我不想要开始工作

的工作,然后找出我搞砸了!


-

最好的问候


无与伦比的新手先生o?o

解决方案



" Mr Newbie" <他** @ now.com>在消息中写道

新闻:eE *************** @ TK2MSFTNGP09.phx.gbl ...

我是仍在考虑这个问题,我发现自己不确定几件事情。

当新用户启动ASP.NET应用程序时,这必须是新的
线。当遇到类中的共享成员时,除非您在该共享成员函数中实例化本地对象时大概设置静态变量,否则系统会维护该对象的本地副本线程(这是对的吗?)。

或许可以更清楚地说明我的观点。在共享成员函数中,如果我有一个共享成员,它声明一个Integer类型的变量a。
实际存储这个整数我假设是在用户的一个线程上
并且不能与任何人混淆(UNLESS)变量是静态的,如Jay所指出的那样。



局部变量在堆栈上分配,这是专属于当前线程的
内存。

David


回答我的问题precisley。


谢谢


-

独特的Mr Newbie o?o

" David Browne" < davidbaxterbrowne没有盆栽 me**@hotmail.com >写在

消息新闻:ei **************** @ TK2MSFTNGP12.phx.gbl ...


新手先生 <他** @ now.com>在消息中写道
新闻:eE *************** @ TK2MSFTNGP09.phx.gbl ...

我还在考虑这个主题,我发现自己不确定几件事情。

当新用户启动ASP.NET应用程序时,这必须在新的
线程上。当遇到类中的共享成员时,除非您在该共享成员函数中实例化本地对象时大概设置静态变量,否则系统会维护该对象的本地副本线程(这是对的吗?)。

或许可以更清楚地说明我的观点。在共享成员函数中,如果我有一个共享成员,它声明一个Integer类型的变量a。
实际存储这个整数我假设是在用户的一个线程上
并且不能与任何人混淆(UNLESS)变量是静态的,如Jay所指出的那样。


局部变量在堆栈上分配,这是专属于当前线程的内存。

David



我对你使用共享这个词感到困惑。并且在相同的

消息中,静态。在VB.Net中,共享表示静态。那么,你是指

到共享吗?如在静态中那样或者其他一些含义?如果不是静态的,什么

定义共享你是什​​么意思?


-

HTH,


Kevin Spencer

微软MVP

..Net开发人员

你可以把鱼带到自行车上,

但你不能让它发臭。


Mr Newbie <他** @ now.com>在消息中写道

新闻:eE *************** @ TK2MSFTNGP09.phx.gbl ...

我是仍在考虑这个问题,我发现自己不确定几件事情。

当新用户启动ASP.NET应用程序时,这必须是新的
线。当遇到类中的共享成员时,除非您在该共享成员函数中实例化本地对象时大概设置静态变量,否则系统会维护该对象的本地副本线程(这是对的吗?)。

或许可以更清楚地说明我的观点。在共享成员函数中,如果我有一个共享成员,它声明一个Integer类型的变量a。
这个整数的实际存储我假设是用户一个线程
并且不能与任何人混淆(UNLESS)变量是静态的,如Jay指出的那样。

这让我变得偏执的原因是我想在我的数据层中广泛使用共享函数来减少代码膨胀和不断实例化。
有没有人看到任何问题。 Cor在早期的帖子中与数据集相关的例子对我来说似乎不对,因为他说数据集将会被覆盖,我不知道这是怎么回事。我决定重新做这个帖子线程重新开始,我希望没有人介意。

抱歉这里有点偏执,但我不想开始
大量的工作然后找出我搞砸了!

- 最好的问候

独特的Mr Newbie o?o



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 o?o

解决方案


"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


That answers my question precisley.

Thank you

--
Best Regards

The Inimitable Mr Newbie o?o
"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



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 o?o



这篇关于在ASP.NET中使用共享类成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆