asp.net中的静态关键字用法? [英] Static keyword usage in asp.net?

查看:79
本文介绍了asp.net中的静态关键字用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解在asp.net中使用静态方法和

属性的含义所以我发现了一篇文章ASP.NET故障排除

应用程序使用静态关键字"

http:/ /support.microsoft.com/?id=893666 )讨论了如果用户同时访问静态方法而看到其他用户数据的可能性

因为值是共享的。


虽然我从未使用它,但我注意到一些SqlHelper函数的一部分

数据访问应用程序块使用静态方法(即ExecuteReader)为什么

如果存在

文章中描述的竞争条件的风险呢?


似乎静态应该在asp.net应用程序中非常谨慎地使用(而不是

说一个桌面智能客户端应用程序,每个用户都有自己的副本

st atic方法/专长)这是一个公平的评估吗?


谢谢

I''m trying to understand the implications of using static methods and
properties in asp.net so I found an article "Troubleshooting ASP.NET
applications with the use of static keywords"
(http://support.microsoft.com/?id=893666) that discusses the possiblity of
users seeing other users data if they access static methods at the same time
because values are shared.

Although I never used it, I noticed that some SqlHelper functions part of
the Data Access application block use static methods (i.e ExecuteReader) Why
would this be if there is a risk of race conditions as described in the
article?

It seems static should be used very sparingly in asp.net app (as opposed to
say a desktop smart client app where each user would have their own copy of
static methods/properies) Is this a fair assessment??

Thanks

推荐答案

你刚才去必须更加了解线程问题,因为

线程是在ASP.Net应用程序中隐式完成的,而不是类似于

a WinForms应用程序,因为应用程序服务器由于通过线程请求处理程序支持多用户,(IIS)具有内在的线程



如果正确实现了<静态方法,那么它将是线程安全的br />
这种用法。基本上,只要该方法在本地创建它的所有

变量并从

池中获取其数据库连接(如果它是DB方法)(它本身就是线程安全),不会有竞争条件,

因为共享资源(连接)是以线程安全的方式处理的,

而所有其他变量使用该方法是在本地创建的,因此不是在方法调用之间共享的。
You are just going to have to be more aware of threading issues, as
threading is implicitly done in an ASP.Net app, as opposed to something like
a WinForms app, since the application server (IIS) is inherently threaded
due to supporting multi-users via threaded request handlers.
A static method is going to be thread-safe if it is properly implemented for
this kind of usage. Basically, as long as the method creates all of its
variables locally and grabs its DB connection (if it''s a DB method) from the
pool (which itself is threadsafe), there isn''t going to be a race condition,
as the shared resources (connections) are handled in a threadsafe manner,
while all other vars used in the method are created locally and thus not
shared across method calls.


因为方法是可执行代码。并且没有更新。问题是

,多个用户可以更新(即变量)。


将ASP.NET应用程序视为MULTIPLE使用的SAME应用程序/>
用户......


-

Patrice


Dave <沓** @ discussions.microsoft.com> écritdansle message de

新闻:FE ********************************* * @ microsof t.com ...
Because a method is "executable code" and is not updated. The problem is
with what multiple users could update (i.e. variables).

See an ASP.NET application as being the SAME application used by MULTIPLE
users...

--
Patrice

"Dave" <Da**@discussions.microsoft.com> a écrit dans le message de
news:FE**********************************@microsof t.com...
我正在尝试理解在asp.net中使用静态方法和
属性的含义,所以我发现了一篇文章ASP故障排除。 NET
使用静态关键字的应用程序
http ://support.microsoft.com/?id = 893666 )讨论了如果用户在相同的
时间访问静态方法而看到其他用户数据的可能性,因为值是共享的。

虽然我从未使用它,但我注意到一些SqlHelper函数部分使用静态方法(即ExecuteReader)
如果有一个
文章中描述的竞争条件的风险?

在asp.net应用程序中应该非常谨慎地使用静态(而不是
来表示桌面智能c) lient app每个用户都有自己的副本
的静态方法/属性)这是一个公平的评估吗?

谢谢
I''m trying to understand the implications of using static methods and
properties in asp.net so I found an article "Troubleshooting ASP.NET
applications with the use of static keywords"
(http://support.microsoft.com/?id=893666) that discusses the possiblity of
users seeing other users data if they access static methods at the same time because values are shared.

Although I never used it, I noticed that some SqlHelper functions part of
the Data Access application block use static methods (i.e ExecuteReader) Why would this be if there is a risk of race conditions as described in the
article?

It seems static should be used very sparingly in asp.net app (as opposed to say a desktop smart client app where each user would have their own copy of static methods/properies) Is this a fair assessment??

Thanks



或者,简单来说,如果你的方法是静态的,你会遇到问题

,因为你使用的是一个类(而不是类的实例)作为

单身而不是作为自足的原子方法的存储库

调用。
Or, in simpler terms, you''ll run into problems if your method is static
because you are using a class (as opposed to an instance of the class) as a
singleton rather than as a respository of self-contained, atomic method
calls.


这篇关于asp.net中的静态关键字用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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