Public Shared variable vs. application state variable -- exactly identical??

I've done several searches on this topic in the forums here, but I'm still not 100% sure I know the answer to this question: is declaring a public shared variable in global.asax the same thing as using Application("xxx")?  If so, is there any reason to use Application state variables at all when you can get all the benefits (eg. code completion) of using the public shared variable?

Thanks,
Steve
0
Stephen_M_Smith
10/7/2003 6:24:15 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

1 Replies
650 Views

Similar Articles

[PageSpeed] 2

I just found this blurb in a Ask Dr. Gui.NET article on MSDN and now I'm more confused than before:

An important note: while it's just fine to use static/Shared methods in ASP.NET applications, you should NOT use static/Shared fields. Shared fields will be shared in an unpredictable manner across instances of your ASP.NET application (in other words, across sessions). This tends to make a real mess, so just don't do it, even if you think you know what you're doing. Instead, use view state or session state, which work predictably and reliably all the time.
I didn't run across this in any posts about this topic in the forum here. Is it really valid?
Thanks,
Steve
0
Stephen_M_Smith
10/8/2003 1:50:41 AM
Reply:

Similar Artilces:

application variable vs static variables
hi, i have some lookup values that will not change frequently, so i thaught of storing it in the application scope or in a static variable of a class and use it. i am sure that this value will not change at all. so which method i can use to improve the performance ie hitting the DB has to be reduced. I know if i store in the application scope the value will be loaded only once and until we reset the iis the value will be in the memory. but how abt static variables? when it will be loaded in to memory and how frequent it will be destroyed? in short, which method to use and why? Thank ...

Shared Variable VS Instance Variable
Dear all, I am a newbie to Powerbuilder. I have a question on the terms of Shared Variable and Instance Variable. What are they? What's the difference between them? I have already looked for them in books and the Internet, but due to a lack of examples, I can't figure them out clearly. Please kindly advise me if possible. Thanks for you kind attention. Best Regards, Someone. An instance variable and a shared variable turn out to be the same *unless* you open multiple instances of your window, say w_1. So, suppose you have an instance window called w_1, with...

Application vs shared vs cached
Hi, I need an application level hashtable. This is to prevent two sessions with the same userid from accessing the web application. Should I do this in Global.asax:Public Shared fgh As Hashtable = New Hashtable()or this:Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Application("cde") = New Hashtable() End Subor this:Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) HttpRuntime.Cache("abc") = New Hashtable() End Sub If the cache method is better, should I still use SyncLock ( I thought the cache o...

variable variables?
Hello! How to make a variable receive an increment in the name? I want to do it for example: I have: Label1->Caption = "1"; Label2->Caption = "2"; Label3->Caption = "3"; Label4->Caption = "4"; And I want to do something like that: for (i=1; i<5; i++) { Label+i->Caption = i; } Any idea? Can I do something like that? Thanks and regards Alexandre Create a vector of pointers to the various objects. In your case below, construct a vector (called Labels) of pointers to TLable long enough to hold pointers to...

variable not a variable
Error:Must declare the variable '@cartDateTime'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@cartDateTime'. Dim connStr As SqlConnection            Dim cmdInsert As SqlCommand            Dim strInsert As String      &n...

variable of variables
Say I have 2 scenarios and I want to use a different variable depending on which scenario applies without coding this logic. So I could have a database table t_variables which has: Scenario: Variable: --------- -------- 1 v_name 2 v_company In my Powerbuilder code I'd have values in v_name & v_company. What I'd like to be able to do is to select which variable to use from the table and assign that to something, e.g. select variable into v_variable from t_variables where scenario = 1 so at this point v_variable would be 'v_name'...

Variable Variables
Hi, Maybe the solution is very simple, but how do I create variable variables in vb.net? I want to use the value of a variable as a part of the name of another variable. A very simple example below: code: Dim a As String a = "1" Label a.Text = "hi" page: <asp:Label id="Label1" runat="server">Label</asp:Label> In need this to change a range of values by using just one loop. I can´t do that without creating a variable variable name. Hi, check out this little demo application I created for you: ...

Global Variables vs. instance variables declared at application object level
There is only one application object instance during the application runtime that is instantiated at the start along with the global variables, so I am looking for what are the major differences, advantages , and disadvantages between Global Variables and instance variables declared for the application object. Thanks I've wondered also about the application instance variables. I think the difference with global vars is very subtle. Maybe too subtle to be of any use. Anyway, you shouldn't be using either one of them :-) Geert 'Darling' Van Damme Moh...

Public Properties with private variables versus public variables
I'm an experienced windows developer, new to web technologies and asp.net, and I see a lot of code in asp.net using public variables, and my first reaction is "yuck!". Is this a normal best practice b/c web apps need the performance advantage? I always expose public properties (getters/setters) that reference private variables, but a more experienced web developer said that was too inefficient, and he said to use public variables. Thanks, and I would welcome any suggestions/references for best practices in asp.net, particularly referencing OOP practices. Well, from my expe...

shared variable or session variable???
I've asked this question on a couple of different forums and usenet and noone has offered a reply, so I thought I'd try it here... I have 2 different web apps that happen to do almost exactly the same things. One I did many months ago and the other is very recent. In both cases, I had data that needed to be available throughout all the functions of the page. Looking at the code, I noticed that in the older one I used a shared variable (woud be static in c#) to hold the needed data. In the newer app, I simply used a session variable. The data itself is a dataTable. My question is:...

another Application starting
Please have a look at the following log my application has made: 9:33:38Application Starting (Application_Start) 9:33:38Application variable 'server' is really null 9:33:39Session Starting (Session_Start) 9:37:12Application Starting (Application_Start) 9:37:12Application variable 'server' is really null 9:37:12Session Starting (Session_Start) So the question is how is it ever possible that another instance of my web application is starting after 5 min when I have session timeout set to 30 min? I have problem with that because in each case the application creates ne...

Use of Application Variable and Session Variable
Hi all, please someone tell me when should a Application variable be used and in what conditions a session variable should be used? regards Subhajit As the name of the variables suggest, an Application variable is suitable when the value of this variable should be available to all users of your application from the point the Application is started for the first time. A Session variable, on the other hand, may be different for different users and only exists for the duration of a users visit to your application or until it times out. Hth.RegardsAndre Colbiornsen ----------------...

shared variable versus global variable
Hi, I plan to implement a little timer service for a certain window class to synchronize some actions between all instances of this class. For some reasons I want to avoid the declaration of a global variable. Now I think about the usage of a shared variable for the service in this window class. In the open event I would check if the shared variable is already instantiated and create the service if necessary. On close of the last window of the class the service should be destroyed from the garbage collector. Do you think that this will work? Thanks for hints Chris Wern...

Passing variables vs session variable
what is the advantage of passing the variable in the url vs storing the variable in a session variable and retrieving it in the second webpage you are accessing?  The variable that you will pass using the QueryString will be visible to the user hence not secured. The value that you put in the Session is not available to the user as it is on the server side and hence more secured. HighOnCodingWanna get high! performance wise does it matter? Just my 2 cents... I remember in college the professors would always harp upon using the Session responsibly. Most of the professors were old...

global variable vs local variable
hi all, i have a scenario like function is called more than 1000 times.in that function i declared a varible and assigning a value .i felt like declare a global varible use it in that function and assign value.which is best.please tell me in performance point of view. thanks in advance  Hai Good Morning you have call  the function  more than 1000 times Better use Global variables, so you can call the function, anywhere.. it has good performance.suppose it you want assign different values to the variables , whenever the function has been called for that use local ...

Web resources about - Public Shared variable vs. application state variable -- exactly identical?? - asp.net.getting-started

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Pre-Christmas job application rush hits Australian public service
Speed required for pre-Christmas job window opening for public servants. Check out who is hiring.

Second visa application 'likely' to be approved
The family of a terminally ill Pakistani student can 'hopefully come to Australia sooner rather than later' says Immigration Minister Peter Dutton. ...

Cloud application adoption increases 71 percent in 2015
The adoption of cloud applications is soaring, up by 71 percent in the last year according to the results of a new survey. The latest Cloud ...

Tashfeen Malik's visa application under scrutiny - Business Insider Deutschland
The US government has released the visa application for Tashfeen Malik, who along with her husband killed 14 people in an attack in San Bernardino, ...

MBA: Mortgage Applications Decrease in Latest MBA Weekly Survey, Purchase Applications up 34% YoY
From the MBA: Mortgage Applications Decrease in Latest MBA Weekly Survey Mortgage applications decreased 1.1 percent from one week earlier, ...

Lawmaker: Immigration Officials Didn’t Fully Vet Tashfeen Malik’s Visa Application
"It’s unacceptable that U.S. Citizenship and Immigration Services did not fully vet Malik’s application and instead sloppily approved her visa," ...

German-Based Spirea Promotes Decentralized PV Applications In Uruguay
... Its technical operations specialist, Laurie Lawrence, pointed out that Uruguay [&hellip German-Based Spirea Promotes Decentralized PV Applications ...

Visa application of San Bernardino shooter released
CNN Visa application of San Bernardino shooter released CNN (CNN) The visa application of one of the San Bernardino shooters was released ...

ZTE to develop smartphone application processors in house
ZTE has stepped up its efforts to internally develop smartphone chipset solutions, aiming to re-capture the title as one of the top-three smartphone ...

Resources last updated: 12/27/2015 4:41:40 PM