Re: Static variables - saving state!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Peter Rilling (peter_at_nospam.rilling.net)
Date: 09/23/04


Date: Thu, 23 Sep 2004 11:46:52 -0700

I think that static variables in ASP.NET will have application scope and
exist until the website stops. If you need to maintain state this way, you
should probably use the Session object which will disappear when the session
dies.

"aiKeith" <aiKeith@discussions.microsoft.com> wrote in message
news:3203DB81-AA63-47C9-9162-8EBF70E0EF90@microsoft.com...
> Hello,
>
> I hate to admit it, but there have been times where I needed to persist a
> value in an asp.net app, and instead of using properties {get:set} I
simply
> changed the variable to static - which maintained the value.
>
> My question is - what are the potential hazards?
>
> ie:
>
> public static string firstName;
> public string LastName;
> private string PhoneNumber;
>
> by doing this above, I can assign the fistName value, post back a page -
and
> still maintain the value..
>
> Im sure (other than performance) I may be playing with danger here.
>
> I have used static quit a bit on classes that do not need instances
(mostly
> my data classes use static method to access/modify data) .. this I
understand.
>
> What I dont exactly get is using static members in a non static class. If
> someone could explain this to me better, that would be great.
>
> thanks,



Relevant Pages

  • Static variables - saving state!
    ... value in an asp.net app, and instead of using properties I simply ... public static string firstName; ... public string LastName; ... my data classes use static method to access/modify data) .. ...
    (microsoft.public.dotnet.general)
  • Re: mess CString content in pWnd->postmessage method
    ... So avoid static variables. ... >If you are certain your worker thread will continue to exist, ... Although I checked the sender end, it sent out the correct string. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Need some basic help with program
    ... public static void main (String[] args) ... Variables you need to access everywhere, you can make static variables ... distracting detail. ...
    (comp.lang.java.help)
  • Re: SessionStatic
    ... Static variables live in the application ... Writing an ASP.NET page that makes use of a static class in a Class ... ..wondering, is it possible to make a static field, static per session. ... public static string Variable; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Variable must be in a Module??
    ... static variables. ... > Module Test ... > Public A As String ... You'll find when you look around the Framework, ...
    (microsoft.public.dotnet.languages.vb)