ASP.NET Global object created twice?

  • Thread starter Thread starter John Ruiz
  • Start date Start date
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
 
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?
 
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?
 
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?
 
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
 
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?
 
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
 
Back
Top