What is better: Static variable V.S. Asp.NET Application Session?

前端 未结 4 1746
难免孤独
难免孤独 2020-12-17 22:41

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) A static variable h

4条回答
  •  暖寄归人
    2020-12-17 22:52

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

    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.

提交回复
热议问题