ASP.NET Global object created twice?

J

John Ruiz

the constructor definition in my Global.asax.cs file contains (among other
things) the following line:

System.Diagnostics.Debug.WriteLine( "Global Constructor ran." );

when I run my web application via the debug menu of VS.NET, my console
prints out the above log message... twice! why does ASP.NET create the
Global object twice, how can I get it to not do this and if it is not
possible, what are viable work arounds?

thankful and stuff,
~ jR
 
N

NoOne

When I tried this, the double construction only happens on the start up of
the application. After that I don't any conctruction ever again. How much of
a problem is this?
 
J

John Ruiz

My Global class has a Dumb object as an attribute. Within
Application_Start(), this object gets instantiated and initialized (
myDumbObject = new Dumb(); ).

But if the Global object is getting created twice, then when I go to use my
Dumb object, I get an error because the Dumb object hasn't been instantiated
in the second Global object.

I consider this a problem, but maybe you do not. "How much" is inherently
relative. At any rate, I "very much" appreciate your time. :)

~ jR


When I tried this, the double construction only happens on the start up of
the application. After that I don't any conctruction ever again. How much of
a problem is this?
 
J

JD

Well you realy didn't explain yourself in your first post and tell us why
this was a problem

After the initial dumb object creation, can you put the dumb object into the
application cache, and reference it from there on subsequent requests?
 
S

Sherif ElMetainy

Hello

ASP.NET uses one Global class instance to serve a single request. After
requests ends the instance is recycled for use by later request. ASP.NET can
create many instances to handle simultaneous requests. To solve you problem
I think making the dumb object static will solve it.

Best regards,

Sherif
 
J

John Ruiz

Hey - where do you get off calling my objects dumb?? Hahaha.

Thanks for the suggestion - I'll try this out and see if anyone around here
comes down on me for it.

~ jR


Well you realy didn't explain yourself in your first post and tell us why
this was a problem

After the initial dumb object creation, can you put the dumb object into the
application cache, and reference it from there on subsequent requests?
 
J

John Ruiz

Hey - who said you could go around calling my objects dumb?? hahaha.

Not sure if circumstances will allow me to arbitrarily turn the dumb object
static, but I will look into this possibility also.

Thanks!
~ jR

Hello

ASP.NET uses one Global class instance to serve a single request. After
requests ends the instance is recycled for use by later request. ASP.NET can
create many instances to handle simultaneous requests. To solve you problem
I think making the dumb object static will solve it.

Best regards,

Sherif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top