|
|
 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

July 17th, 2007, 02:48 AM
|
|
Registered User
|
|
Join Date: May 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem with static variables behaviour
Hi
I have made an asp.net application in which i have use static variables so i can use these values from one page to other
page or on the same page (on the same page bcoz if i use simple variables then on page postback these variables loss
their data).
Now I publish this application on local intranet. now suppose if i initialize this varibale say( myStaticVar )to 0 as follow
myStaticVar =0.
if there are two users that access this application and one user change its value to 1
myStaticVar =1
then the problem occurs that the second user also get the change value.This means the application is not thread safe. how
this problem can reslove to seperate each user's values to other user's data. as i have declare so many static variables in
my application.
Thanks in advance.
|

July 17th, 2007, 08:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,046
Thanks: 5
Thanked 45 Times in 44 Posts
|
|
hi there.. you better store this data in cookies or session variables, to avoid passing data from one user to another...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|

July 18th, 2007, 12:09 PM
|
|
Authorized User
|
|
Join Date: Jul 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Static variables are independent of any particular object.
They are bound to classes & not objects.
dont use static variables,becuase what is happening is how static variabls behave
|

July 18th, 2007, 10:22 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
I don't think that "thread safe" is being used correctly here. Either way, whether the static var is or isn't thread safe is irrelevant.
Your web assemblies are loaded in one application, the ASP.NET worker process. So the static variables are in the scope of all page requests that come in.
You should really avoid using static variables. Instead you should be using any other means for user based values, which could be viewstate, session or anything else persistent (like a database).
Is there a reason you have chosen static vars instead of something like session?
-Peter
|

July 21st, 2007, 02:56 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: Islamabad, Punjab, Pakistan.
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear u can use hidden labels(s) in order to store values. Static variables are shared variables and they keep thier last stored value as long as application is running state.
Regards
Ali Irafn
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |