473,385 Members | 1,757 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,385 software developers and data experts.

Static Keyword

I wasn't expecting this behavior from a static variable. A thread wrapped by
a class has a couple static variables in a webform. When the thread runs and
the browser closes, the static variable is still hanging around. I was under
the mistaken impression that static was tied to the session, that it would
go away once the browser closes. It seems to be tied to the application
object instead.

Re-launching the application retrieved the last saved value for the previous
session. I wasn't expecting that. I wonder if I log in with a different
username, will I get that static value from the last session? If so I need
to be worried about synch issues then with multi-users.

Anybody?
Nov 15 '05 #1
3 6604

"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:eZ**************@TK2MSFTNGP12.phx.gbl...
I wasn't expecting this behavior from a static variable. A thread wrapped by a class has a couple static variables in a webform. When the thread runs and the browser closes, the static variable is still hanging around. I was under the mistaken impression that static was tied to the session, that it would
go away once the browser closes. It seems to be tied to the application
object instead.

Re-launching the application retrieved the last saved value for the previous session. I wasn't expecting that. I wonder if I log in with a different
username, will I get that static value from the last session? If so I need
to be worried about synch issues then with multi-users.


Alvin,

The static variable will be around for the lifetime of the application
domain, since its a web application you'll have to have some type of locking
mechanism unless it is for readonly data, in which case you'll want to make
sure that the initial load is thread safe

hth
andrew
Nov 15 '05 #2


Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Alvin Bruney <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote:
I wasn't expecting this behavior from a static variable. A thread wrapped by
a class has a couple static variables in a webform. When the thread runs and
the browser closes, the static variable is still hanging around. I was under
the mistaken impression that static was tied to the session, that it would
go away once the browser closes. It seems to be tied to the application
object instead.


It's actually tied to the AppDomain, same as normal. There's nothing
magical about ASP.NET types as opposed to other types.

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

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

Similar topics

29
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static...
3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
3
by: Bas Wassink | last post by:
Hello there, I'm having trouble understanding a warning produced by 'splint', a code-checker. The warning produced is: keywords.c: (in function keyw_get_string) keywords.c:60:31: Released...
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
10
by: shantanu | last post by:
Hi, How can we declare a static variable or function declared in one source file, which is to be used in other source file?
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
32
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only...
2
by: DaTurk | last post by:
Hi, I have an interesting issue, well, it's not really an issue, but I'd like to understand the mechanics of what's going on. I have a file, in CLI, which has a class declared, and a static...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.