ASP.NET Global object created twice?

Discussion in 'ASP .Net' started by John Ruiz, Nov 4, 2003.

  1. John Ruiz

    John Ruiz Guest

    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
     
    John Ruiz, Nov 4, 2003
    #1
    1. Advertising

  2. John Ruiz

    NoOne Guest

    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?


    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
     
    NoOne, Nov 4, 2003
    #2
    1. Advertising

  3. John Ruiz

    John Ruiz Guest

    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


    "NoOne" <> wrote in message
    news:#...
    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?


    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
     
    John Ruiz, Nov 4, 2003
    #3
  4. John Ruiz

    JD Guest

    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?

    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
    > "NoOne" <> wrote in message
    > news:#...
    > 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?
    >
    >
    > "John Ruiz" <> wrote in message
    > news:...
    > >
    > > 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
    > >
    > >

    >
    >
    >
     
    JD, Nov 4, 2003
    #4
  5. 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



    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
    > "NoOne" <> wrote in message
    > news:#...
    > 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?
    >
    >
    > "John Ruiz" <> wrote in message
    > news:...
    > >
    > > 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
    > >
    > >

    >
    >
    >
     
    Sherif ElMetainy, Nov 5, 2003
    #5
  6. John Ruiz

    John Ruiz Guest

    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


    "JD" <> wrote in message
    news:QLWpb.109189$e01.374913@attbi_s02...
    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?

    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
    > "NoOne" <> wrote in message
    > news:#...
    > 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?
    >
    >
    > "John Ruiz" <> wrote in message
    > news:...
    > >
    > > 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
    > >
    > >

    >
    >
    >
     
    John Ruiz, Nov 5, 2003
    #6
  7. John Ruiz

    John Ruiz Guest

    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

    "Sherif ElMetainy" <> wrote in message
    news:...
    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



    "John Ruiz" <> wrote in message
    news:...
    >
    > 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
    >
    >
    > "NoOne" <> wrote in message
    > news:#...
    > 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?
    >
    >
    > "John Ruiz" <> wrote in message
    > news:...
    > >
    > > 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
    > >
    > >

    >
    >
    >
     
    John Ruiz, Nov 5, 2003
    #7
  8. John Ruiz

    NoOne Guest

    I was actually laughing to myself when I wrote that message...

    "John Ruiz" <> wrote in message
    news:u4yU#...
    > 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
    >
    >
    > "JD" <> wrote in message
    > news:QLWpb.109189$e01.374913@attbi_s02...
    > 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?
    >
    > "John Ruiz" <> wrote in message
    > news:...
    > >
    > > 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
    > >
    > >
    > > "NoOne" <> wrote in message
    > > news:#...
    > > 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?
    > >
    > >
    > > "John Ruiz" <> wrote in message
    > > news:...
    > > >
    > > > 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
    > > >
    > > >

    > >
    > >
    > >

    >
    >
    >
     
    NoOne, Nov 5, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ash

    Cookie created twice

    Ash, Feb 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,553
  2. Manuel Vázquez Acosta

    Global constructor called twice

    Manuel Vázquez Acosta, Jan 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    552
    Ryan Trudelle-Schwarz
    Jan 22, 2005
  3. Ulf Heyder
    Replies:
    0
    Views:
    580
    Ulf Heyder
    Oct 16, 2003
  4. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    410
    Kiuhnm
    Apr 1, 2006
  5. User1014
    Replies:
    3
    Views:
    197
    Richard Cornford
    Dec 1, 2006
Loading...

Share This Page