简体   繁体   English

asp.net并发访问静态变量

[英]asp.net concurrent access to static var

Static vars can be read simultaneously by users? 用户可以同时读取静态变量吗?

     public static ConcurrentDictionary<string, object> aStaticDictionary= new ConcurrentDictionary<string, object>();

When an user read the dictionary 用户阅读字典时

    aStaticDictionary["key"]

Concurrent requests are queued? 并发请求已排队?

Yes, with some caveats. 是的,有一些警告。 Static vars can be read by multiple threads but aren't shared between processes. 静态变量可以由多个线程读取,但不能在进程之间共享。 That's important if you've configured your IIS app pool to have more than one worker process. 如果您已将IIS应用程序池配置为具有多个工作进程,则这一点很重要。

You can't predict the order that different threads will access the dictionary. 您无法预测不同线程将访问字典的顺序。 The ConcurrentDictionary only guarantees that reads which are made simultaneously with writes to the dictionary won't cause problems whereas they may have done if use used the standard Dictonary class. ConcurrentDictionary仅保证与对字典的写入同时进行的读取不会引起问题,而如果使用标准Dictonary类,则可能会造成问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM