0

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?

4

1 回答 1

0

是的,有一些警告。静态变量可以被多个线程读取,但不能在进程之间共享。如果您已将 IIS 应用程序池配置为拥有多个工作进程,这一点很重要。

您无法预测不同线程访问字典的顺序。ConcurrentDictionary 仅保证与对字典的写入同时进行的读取不会导致问题,而如果使用标准 Dictonary 类,它们可能会发生问题。

于 2013-06-08T17:40:00.317 回答