tags:

views:

1117

answers:

3

Hi

WorkAround:

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

Problem: 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.

Thanks Karthikeyan.

+2  A: 

Static variables keep their values for the duration of the application domain.

It will survive many browser sessions until you restart the web server (IIS) or until it restarts on its own (when it decides it needs to refresh its used resources).

Developer Art
And sometimes when closing VS2008 the Cassini server will still be active and not unloaded. Boy that makes for some fun global.asax debugging.
Radu094
Never happened to me happily.
Developer Art
+2  A: 

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.

Darin Dimitrov
A: 

Static variables are valid for the entire AppDomain.

Closing VS 2008 IDE and/or stopping debugging is not always enough to get the AppDomain that is hosting your website to such down. (Even when the website is hosted in the Vs 2008 tests server.

One easy solution is the "touch" the web.config file. (E.g. add a space and save it)

That will get the next request processed in a new app-domain.

Ian Ringrose