473,573 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static object in Global.asax vs Application State

Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have a
localy defined DataSet LSOBJ in Global.asax which I am storing in Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan
Nov 19 '05 #1
8 4853
Hello
I think both object have same scope.

bhawin13

Nov 19 '05 #2
On Tue, 5 Jul 2005 20:17:02 -0700, Vishwanathan Raman
<Vi************ ***@discussions .microsoft.com> wrote:
Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have a
localy defined DataSet LSOBJ in Global.asax which I am storing in Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
The Application object is basically a hashtable - it stores object
references that you can retrieve with a key value. The Application
object also has some thread safety built-in, whereas a static member
does not.

IIS doesn't know what is happening inside the .NET runtime.
Are both objects stored in different memory spaces?
What do you mean by memory space?
Both objects will live inside the memory space for your application
domain.
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #3
I'm not sur what is it you call "Applicatio n State". What I can say is that a
static variable in the Global.asax file will be shared by the whole ASPNET
application, but there are many instances of the Global class running in the
ASPNET application. Each of them serves one request at a time, but they are
different instances. Could you provide a code sample ?

Regards
François

"Vishwanath an Raman" wrote:
Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have a
localy defined DataSet LSOBJ in Global.asax which I am storing in Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan

Nov 19 '05 #4
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have
a
localy defined DataSet LSOBJ in Global.asax which I am storing in
Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan

Nov 19 '05 #5
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have
a
localy defined DataSet LSOBJ in Global.asax which I am storing in
Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


Nov 19 '05 #6
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
Hi

I have a declared a static DataSet object SOBJ in Global.asax.I also have
a
localy defined DataSet LSOBJ in Global.asax which I am storing in
Application
State.Is there any technical differences in the way both the objects are
handled by IIS.
Are both objects stored in different memory spaces?
I can access both the objects in my web page.

I will be grateful if some one can help me understand the difference.

Regards
Vishwanathan


Nov 19 '05 #7
Francois:
Thanks for the insight.I create both the objects in Global.asax file.
eg

public static DataSet DataDictionaryD s = new DataSet();

private DataSet pvtDataDictiona ryDs = new DataSet();

Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;

pvtDataDictiona ryDs =null;

I find that the one in Application State expires and the static remains
active.


"François Lemaire" wrote:
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:
Hi!

I think you'd find out a lot if you check out this page:
http://msdn.microsoft.com/library/en...asp?frame=true

Also, you might get better performance if you use the HttpContext.Cac he
object instead of the Application.Con tents object.. (Although you'd use some
more memory when the application gets a lot of users)
You find information about both on the link above. :)

HTH,
Lars-Erik

"Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
message news:94******** *************** ***********@mic rosoft.com...
> Hi
>
> I have a declared a static DataSet object SOBJ in Global.asax.I also have
> a
> localy defined DataSet LSOBJ in Global.asax which I am storing in
> Application
> State.Is there any technical differences in the way both the objects are
> handled by IIS.
> Are both objects stored in different memory spaces?
> I can access both the objects in my web page.
>
> I will be grateful if some one can help me understand the difference.
>
> Regards
> Vishwanathan

Nov 19 '05 #8
I'd say it depends on the time you call :
Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;
If you call it in the Global.asax constructor, then each time an Global.asax
object is created, it is replaced (and if you have multiple users at the same
time, it can be often). If you call it in Application_Sta rt, it will be
created only when the first HttpApplication is created, thus only once per
application domain creation. I don't think it's a good idea for the
pvtDataDictiona ryDs object to be an instance member of the Global.asax class
; it should not be garbage collected when the Global.asax object is, since it
is referenced in your HttpApplication State object, but who knows, maybe the
link between your object and the HttpApplication State object is a weak
reference, not valid for the garbage collector.

Try the following :

protected void Application_Sta rt(Object sender, EventArgs e) {
DataSet pvtDataDictiona ryDs = new DataSet();
// Load it
Application.Loc k();
Application["pvtDataDiction aryDs"]= pvtDataDictiona ryDs ;
Application.Unl ock();
}

and see what happens... If the object expires, it means that all objects put
into HttpApplication State that are not referenced outside it end up garbage
collected ! I would call that a bug...

"Vishwanath an Raman" wrote:
Francois:
Thanks for the insight.I create both the objects in Global.asax file.
eg

public static DataSet DataDictionaryD s = new DataSet();

private DataSet pvtDataDictiona ryDs = new DataSet();

Application["pvtDataDiction aryDs "]= pvtDataDictiona ryDs ;

pvtDataDictiona ryDs =null;

I find that the one in Application State expires and the static remains
active.


"François Lemaire" wrote:
Static objects in Global.asax as for any class are created when the class is
first accessed after the application domain has been created, eg when the
first page is accessed after the application started. They are discarded and
recreated if the application domain is recreated (this happens when the
ASPNET application restarts, for example if you have changed your web.config
or if the worker process restarts).

If I read the documentation for HttpApplication State, it says that one and
only one HttpApplication State object is created per ASPNET application, and
it is created when a page is first accessed. For me, this is the exact same
thing as a static variable in Global.asax. So, for me, both static variables
in Global.asax and HttpApplication State are static singletons that reside
inside the application domain of your ASPNET application.

I think that if it looks like HttpApplication State expires, it may be
because your worker process is recycled (it can happen when it outgrows a
memory limit set in the config file, or lives for longer than a time
specified in the config file), but then again, in this case, your static
variables are recreated too.

Don't forget that since both these variables are static, they are shared by
all instances, and need to be locked before any access (read or write). When
do you create the object you put into the HttpApplication State ? When do you
create the static object in Global.asax ? I think the solution to your
problem lies here. If you provide the source code, maybe I will be able to
sort it out.

Hope this Helps

François

"Vishwanath an Raman" wrote:
I am facing a problem with the Application State.It expires but I found that
static objects in Global.asax do not expire.I wanted a technical claification
if they were maintained in different mem spaces.

"Lars-Erik Aabech" wrote:

> Hi!
>
> I think you'd find out a lot if you check out this page:
> http://msdn.microsoft.com/library/en...asp?frame=true
>
> Also, you might get better performance if you use the HttpContext.Cac he
> object instead of the Application.Con tents object.. (Although you'd use some
> more memory when the application gets a lot of users)
> You find information about both on the link above. :)
>
> HTH,
> Lars-Erik
>
> "Vishwanath an Raman" <Vi************ ***@discussions .microsoft.com> wrote in
> message news:94******** *************** ***********@mic rosoft.com...
> > Hi
> >
> > I have a declared a static DataSet object SOBJ in Global.asax.I also have
> > a
> > localy defined DataSet LSOBJ in Global.asax which I am storing in
> > Application
> > State.Is there any technical differences in the way both the objects are
> > handled by IIS.
> > Are both objects stored in different memory spaces?
> > I can access both the objects in my web page.
> >
> > I will be grateful if some one can help me understand the difference.
> >
> > Regards
> > Vishwanathan
>
>
>

Nov 19 '05 #9

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

Similar topics

25
5141
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I wanna use global.asax) --- Would you declare your static var as --- public static int x ;
3
7168
by: Faisal | last post by:
Hi. I'm in the process of moving an application from ASP to ASP.NET, & I'm writing in VB, using VS.NET. I'm new to the .NET framework & have a basic question regarding static objects defined in global.asax. In the global.asax file I want to declare some static objects (like an ADODB.Connection, an ADODB.Recordset, a...
7
1541
by: Andrea Williams | last post by:
I would like to be able to create a singleton when using my Error Handling object. It uses a static Instance() method to return the currently activated object. But my question is, since it is static, it is shared between users on a web site? That I would not like since each user needs to have their own instance. Does anyone know the...
8
6792
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx code-behind and in business logic (C# classes used by the aspx) lose their value. I cannot reproduce this on our development server, so I cannot...
5
1994
by: Pross | last post by:
I've got an ASP.NET application and I need some information on every page like the user's name as well as a collection listing which sections of the application the user has access to. I could store the user name in a regular session variable but the collection varies in size based on the user and could grow in the future as the application...
15
2457
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like...
2
5195
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb file, and what would I do to access it? (I am using VB.NET for my code) Thanks. -- Nathan Sokalski njsokalski@hotmail.com...
1
4465
by: romeo_a_casiple | last post by:
I'm looking to create an static object that has application scope and be able to access that static object from my web service. I understand there are two ways to do this : 1) use the object tag in the global.asax, such as: <object id="objObject" runat="server" class="TestApplication.MyClass" scope="Application" />
6
2372
by: depalau | last post by:
I'm running into some issues on maintaining a static variable across the lifetime of a web service and I was wondering if anyone could help. Background: We have developed a C#/1.1 web service running on IIS 5/6 that interfaces with a 3rd party DLL referenced by using the DLLImport attribute. Interacting with this 3rd party software...
0
7670
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7987
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8180
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7740
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6363
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5263
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3703
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2167
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.