本文介绍了Asp.net静态变量生命跨越时间和刷新回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方法:

我已经声明一个类级别的公共静态变量,并在ASP.NET 3.5的环境值0初始化
在负载情况下我递增1变量的

I have declared a class level Public static variable and initialized with a value 0 in the environment of ASP.NET 3.5In load event I Incremented by 1 of that variable

问题:


  1. 让页面刷新,甚至在回发,我收到该变量的最新值。
    声明为静态,变量没有得到通过页面刷新和重置回发

  2. 我只是关闭浏览器,然后关闭VS 2008 IDE - 即使当我重新打开,重新运行相同的Web应用程序,我得到最后的增加值,而不是0。
    我想知道这是怎么可能后,我关闭应用程序。

  1. After getting page refresh and even Postback, I am getting latest values of that variable.A variable declared as STATIC , not getting reset by Page refresh and Postback?
  2. I just close the browser and close the VS 2008 IDE - even though while i am reopen, rerun the same web application, I am getting last incremented value, Not 0.I am wondering how this is possible after i close application.

能否请您对这个有所帮助。

Could you please help on this.

推荐答案

静态变量是适用于整个AppDomain中。当您关闭浏览器,因为它继续到Web服务器上执行不关闭应用程序。哦,忘了提:尽量避免使用多线程应用程序的静态变量没有适当的锁定机制,或者你可能会遇到竞争条件

Static variables are valid for the entire AppDomain. When you close your browser you don't close the application as it continues to execute on the web server. Oh and forgot to mention: try to avoid using static variables in multi-threaded applications without proper locking mechanisms or you may run into race conditions.

这篇关于Asp.net静态变量生命跨越时间和刷新回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 00:12