什么是更好的:静态变量V.S. Asp.NET应用程序会话? [英] What is better: Static variable V.S. Asp.NET Application Session?

查看:170
本文介绍了什么是更好的:静态变量V.S. Asp.NET应用程序会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说你要共享一些资源,比如一个类或ASP.NET Web应用程序中的所有线程/会话变量。什么是好?

Say you want to share some resource, like a class or a variable across all threads/sessions within a ASP.NET web application. What is better?

1),具有线程安全的访问到静态变量静态变量?

1) A static variable having thread-safe accessors to that static variable?

2)或ASP.NET应用程序会话变量?

2) Or a ASP.NET application session variable?

推荐答案

如果你只拥有其中之一,几乎没有什么差别。

If you only have one of those, there is little difference.

如果你有几个,你应该使用静态变量,而不是应用变量。在 Application.Lock 方法将锁定的所有应用的变量,而您可以使用不同的syncronisition为您的静态变量标识符,这样,每个锁只影响code访问特定的变量。

If you have several, you should use static variables rather than Application variables. The Application.Lock method will lock all Application variables, while you can use separate syncronisition identifiers for your static variables, so that each lock only affects the code that accesses that specific variable.

这篇关于什么是更好的:静态变量V.S. Asp.NET应用程序会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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