p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2007, 02:48 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 17th, 2007, 08:30 AM
Friend of Wrox
Points: 6,793, Level: 35
Points: 6,793, Level: 35 Points: 6,793, Level: 35 Points: 6,793, Level: 35
Activity: 13%
Activity: 13% Activity: 13% Activity: 13%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,046
Thanks: 5
Thanked 45 Times in 44 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 18th, 2007, 12:09 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 18th, 2007, 10:22 PM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old 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
Send a message via MSN to aliirfan84
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 02:48 PM
Declaring static variables in ASP lakshmi_annayappa ASP.NET 1.0 and 1.1 Basics 1 May 24th, 2007 07:49 AM
Static Variables For HTML Header Parmy XSLT 1 February 20th, 2006 03:46 PM
who destroy static variables(no instance of class) MikoMax J2EE 1 March 31st, 2004 08:01 AM
A problem with static data members in c++ amotsn C++ Programming 2 August 20th, 2003 03:22 AM



All times are GMT -4. The time now is 12:50 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc