473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

time static variable value is retained

Hi all,
I have written a small code in which i declare a static int variable and
increment its value by one each time i click on a button. actually i use the
int variable value in a particular URL so that i can browse to diff URL each
time i click the button. Hope you understand the scenario.
So here my question is how long is the value of the static variable
retained from the time i click on the button, because what i observe is when
the value of the in variable (static) goes from 1 to suppose 34 and there i
stop clicking and after may be 15 min i again click the button the value of
the int variable is again back to 1. So is there any way i can avoid this
from happening ? and what is the time limit the value of the variable is
retained.
here is the code.

static int cityID=1;
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("http://chicago.craigslist.org/cgi-bin/search?areaID=" +
cityID.ToString()
+"&subAreaID=0&query=entry+level%2C+asp.net%2C+c%2 3&cat=jjj",false);
cityID++;
}
--
Never Say Die
Nov 17 '05 #1
3 2506
Helpseeker,

Static variables live for the life of the application domain. In
ASP.NET, the only reason the variable would reset is because the application
is resetting itself on the server side. This is most likely due to changes
which cause recompilation of the pages/assemblies.

If you can't control when the app is brought up/shut down, then you
might want to store this variable in a file, or some persistent medium, and
then fetch it when you need it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Helpseeker" <He********@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
Hi all,
I have written a small code in which i declare a static int variable and
increment its value by one each time i click on a button. actually i use
the
int variable value in a particular URL so that i can browse to diff URL
each
time i click the button. Hope you understand the scenario.
So here my question is how long is the value of the static variable
retained from the time i click on the button, because what i observe is
when
the value of the in variable (static) goes from 1 to suppose 34 and there
i
stop clicking and after may be 15 min i again click the button the value
of
the int variable is again back to 1. So is there any way i can avoid this
from happening ? and what is the time limit the value of the variable is
retained.
here is the code.

static int cityID=1;
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("http://chicago.craigslist.org/cgi-bin/search?areaID=" +
cityID.ToString()
+"&subAreaID=0&query=entry+level%2C+asp.net%2C+c%2 3&cat=jjj",false);
cityID++;
}
--
Never Say Die

Nov 17 '05 #2
Nicholas,
Actually the IIS server is on my local laptop itself. IIS is up an running
continuously, its not being shutdown. Yes storing in a file is always a
solution, but i was wondering why the variable value was resetting. Was just
curious to know why that was happening.
Thnks,
Helpseeker

"Nicholas Paldino [.NET/C# MVP]" wrote:
Helpseeker,

Static variables live for the life of the application domain. In
ASP.NET, the only reason the variable would reset is because the application
is resetting itself on the server side. This is most likely due to changes
which cause recompilation of the pages/assemblies.

If you can't control when the app is brought up/shut down, then you
might want to store this variable in a file, or some persistent medium, and
then fetch it when you need it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Helpseeker" <He********@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
Hi all,
I have written a small code in which i declare a static int variable and
increment its value by one each time i click on a button. actually i use
the
int variable value in a particular URL so that i can browse to diff URL
each
time i click the button. Hope you understand the scenario.
So here my question is how long is the value of the static variable
retained from the time i click on the button, because what i observe is
when
the value of the in variable (static) goes from 1 to suppose 34 and there
i
stop clicking and after may be 15 min i again click the button the value
of
the int variable is again back to 1. So is there any way i can avoid this
from happening ? and what is the time limit the value of the variable is
retained.
here is the code.

static int cityID=1;
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("http://chicago.craigslist.org/cgi-bin/search?areaID=" +
cityID.ToString()
+"&subAreaID=0&query=entry+level%2C+asp.net%2C+c%2 3&cat=jjj",false);
cityID++;
}
--
Never Say Die


Nov 17 '05 #3
Helpseeker <He********@discussions.microsoft.com> wrote:
Actually the IIS server is on my local laptop itself. IIS is up an running
continuously, its not being shutdown. Yes storing in a file is always a
solution, but i was wondering why the variable value was resetting. Was just
curious to know why that was happening.


It's not a case of IIS shutting down completely, it's a case of the
AppDomain recycling, which it does automatically on occasion and when
you have new code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
12
by: codefixer | last post by:
Hello: I am trying to understand the use of static in this program. http://nanocrew.net/sw/nscdec.c for "inverse" matrix. What difference would it make if it were not static and just "const...
4
by: abCSharp | last post by:
I understand that static variables have app-domain scope. Till the app-domain is in memory, the static variable will be in memory. When are the app-domains unloaded is the question. I have read...
6
by: The8thSense | last post by:
how to declare static varible and static method inside a class ? i try "public static ABC as integer = 10" and it said my declaration is invalid Thanks
11
by: dis_is_eagle | last post by:
hi...i am new to c programming....please explain me as to why should an character array be declared as static...thanx...eric
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
13
by: =?Utf-8?B?bWFyaw==?= | last post by:
Consider this a continuation of 2/27/2007 thread by Zytan entitled"Subject: Does C# have static local variables like C++?" In C++: void mysub() { static double x; blah; blah; }
32
by: mdh | last post by:
Hi all, When I try and initialize this static array, as in: void itoa_recursively(int n, char *s){ static char *p = s; it fails, yet this:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.