Application_OnStart event

Discussion in 'ASP .Net' started by Marek, May 9, 2004.

  1. Marek

    Marek Guest

    Hi,

    Is Application_OnStart event hadler guaranteed to finish its execution
    before another HttpApplication object is brought into life?

    Marek
    Marek, May 9, 2004
    #1
    1. Advertising

  2. No such guarantee is made. I think there is some confusion in the question
    as well.

    The application_onstart event handler is an event which fires when a request
    is paired with an httpapplication instance. The guarantee is only that this
    request will be associated with this one httpapplication instance, that is,
    sequential processing thru the http pipeline until the request is serviced
    fully by that specific httpapplication instance. Each request/instance pair
    is handled on any available thread from the threadpool. The pairing process
    is not
    sequential.

    The responsibility of pairing falls to the httpruntime object. The
    httpruntime object can handle many simultaneous concurrent
    requests - limited only by the available threads in the threadpool
    responsible for servicing requests. In this case, each request gets paired
    with an httpapplication instance. If the httpruntime could only respond to
    one request at a time, this would create a bottleneck under load. Once a
    request has been received, there is an implicit guarantee that the request
    can be associated with only one httpapplciation object.



    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Marek" <> wrote in message
    news:wvinc.550$...
    > Hi,
    >
    > Is Application_OnStart event hadler guaranteed to finish its execution
    > before another HttpApplication object is brought into life?
    >
    > Marek
    >
    >
    Alvin Bruney [MVP], May 9, 2004
    #2
    1. Advertising

  3. Marek

    Marek Guest

    Hi Alvin,

    Thank you for your explanation. Still, I don't understand something.
    Application_OnStart event is raised only ONCE on the first instance of
    HttpApplication. Right?
    I saw many examples of code where they perform some global initialization in
    this handler
    (such as reading config files, remote configuration to name a few). However,
    I didn't see any prevention against
    other HttpApplication instaces access the results of configuration BEFORE
    Application_OnStart event
    handler ends its execution. So I came to the question I asked. Could you
    explain where I'm making
    a mistake?

    Marek

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > No such guarantee is made. I think there is some confusion in the question
    > as well.
    >
    > The application_onstart event handler is an event which fires when a

    request
    > is paired with an httpapplication instance. The guarantee is only that

    this
    > request will be associated with this one httpapplication instance, that

    is,
    > sequential processing thru the http pipeline until the request is serviced
    > fully by that specific httpapplication instance. Each request/instance

    pair
    > is handled on any available thread from the threadpool. The pairing

    process
    > is not
    > sequential.
    >
    > The responsibility of pairing falls to the httpruntime object. The
    > httpruntime object can handle many simultaneous concurrent
    > requests - limited only by the available threads in the threadpool
    > responsible for servicing requests. In this case, each request gets paired
    > with an httpapplication instance. If the httpruntime could only respond to
    > one request at a time, this would create a bottleneck under load. Once a
    > request has been received, there is an implicit guarantee that the request
    > can be associated with only one httpapplciation object.
    >
    >
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Marek" <> wrote in message
    > news:wvinc.550$...
    > > Hi,
    > >
    > > Is Application_OnStart event hadler guaranteed to finish its execution
    > > before another HttpApplication object is brought into life?
    > >
    > > Marek
    > >
    > >

    >
    >
    >
    >
    Marek, May 9, 2004
    #3
  4. The framework guarantees that, regardless of concurrent requests, the
    application object will be initialized only once per application domain.
    This happens when the first request is received. If two requests are
    received at the same time, the runtime uses a spin-lock to force one request
    to wait while the other is serviced guaranteeing threadsafety.

    Now, once that initialization has occurred, its an open field where thread
    access/concurrency is concerned so care must be taken for objects with
    global scope in the application object. Good question. I had to think about
    this for a while.

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Marek" <> wrote in message
    news:V3vnc.619$%...
    > Hi Alvin,
    >
    > Thank you for your explanation. Still, I don't understand something.
    > Application_OnStart event is raised only ONCE on the first instance of
    > HttpApplication. Right?
    > I saw many examples of code where they perform some global initialization
    > in
    > this handler
    > (such as reading config files, remote configuration to name a few).
    > However,
    > I didn't see any prevention against
    > other HttpApplication instaces access the results of configuration BEFORE
    > Application_OnStart event
    > handler ends its execution. So I came to the question I asked. Could you
    > explain where I'm making
    > a mistake?
    >
    > Marek
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:...
    >> No such guarantee is made. I think there is some confusion in the
    >> question
    >> as well.
    >>
    >> The application_onstart event handler is an event which fires when a

    > request
    >> is paired with an httpapplication instance. The guarantee is only that

    > this
    >> request will be associated with this one httpapplication instance, that

    > is,
    >> sequential processing thru the http pipeline until the request is
    >> serviced
    >> fully by that specific httpapplication instance. Each request/instance

    > pair
    >> is handled on any available thread from the threadpool. The pairing

    > process
    >> is not
    >> sequential.
    >>
    >> The responsibility of pairing falls to the httpruntime object. The
    >> httpruntime object can handle many simultaneous concurrent
    >> requests - limited only by the available threads in the threadpool
    >> responsible for servicing requests. In this case, each request gets
    >> paired
    >> with an httpapplication instance. If the httpruntime could only respond
    >> to
    >> one request at a time, this would create a bottleneck under load. Once a
    >> request has been received, there is an implicit guarantee that the
    >> request
    >> can be associated with only one httpapplciation object.
    >>
    >>
    >>
    >> --
    >> Regards,
    >> Alvin Bruney
    >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    >> Got tidbits? Get it here... http://tinyurl.com/27cok
    >> "Marek" <> wrote in message
    >> news:wvinc.550$...
    >> > Hi,
    >> >
    >> > Is Application_OnStart event hadler guaranteed to finish its execution
    >> > before another HttpApplication object is brought into life?
    >> >
    >> > Marek
    >> >
    >> >

    >>
    >>
    >>
    >>

    >
    >
    Alvin Bruney [MVP], May 10, 2004
    #4
  5. Marek

    Marek Guest

    Thank you. Where could I read more about it?

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > The framework guarantees that, regardless of concurrent requests, the
    > application object will be initialized only once per application domain.
    > This happens when the first request is received. If two requests are
    > received at the same time, the runtime uses a spin-lock to force one

    request
    > to wait while the other is serviced guaranteeing threadsafety.
    >
    > Now, once that initialization has occurred, its an open field where thread
    > access/concurrency is concerned so care must be taken for objects with
    > global scope in the application object. Good question. I had to think

    about
    > this for a while.
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Marek" <> wrote in message
    > news:V3vnc.619$%...
    > > Hi Alvin,
    > >
    > > Thank you for your explanation. Still, I don't understand something.
    > > Application_OnStart event is raised only ONCE on the first instance of
    > > HttpApplication. Right?
    > > I saw many examples of code where they perform some global

    initialization
    > > in
    > > this handler
    > > (such as reading config files, remote configuration to name a few).
    > > However,
    > > I didn't see any prevention against
    > > other HttpApplication instaces access the results of configuration

    BEFORE
    > > Application_OnStart event
    > > handler ends its execution. So I came to the question I asked. Could you
    > > explain where I'm making
    > > a mistake?
    > >
    > > Marek
    > >
    > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > news:...
    > >> No such guarantee is made. I think there is some confusion in the
    > >> question
    > >> as well.
    > >>
    > >> The application_onstart event handler is an event which fires when a

    > > request
    > >> is paired with an httpapplication instance. The guarantee is only that

    > > this
    > >> request will be associated with this one httpapplication instance, that

    > > is,
    > >> sequential processing thru the http pipeline until the request is
    > >> serviced
    > >> fully by that specific httpapplication instance. Each request/instance

    > > pair
    > >> is handled on any available thread from the threadpool. The pairing

    > > process
    > >> is not
    > >> sequential.
    > >>
    > >> The responsibility of pairing falls to the httpruntime object. The
    > >> httpruntime object can handle many simultaneous concurrent
    > >> requests - limited only by the available threads in the threadpool
    > >> responsible for servicing requests. In this case, each request gets
    > >> paired
    > >> with an httpapplication instance. If the httpruntime could only respond
    > >> to
    > >> one request at a time, this would create a bottleneck under load. Once

    a
    > >> request has been received, there is an implicit guarantee that the
    > >> request
    > >> can be associated with only one httpapplciation object.
    > >>
    > >>
    > >>
    > >> --
    > >> Regards,
    > >> Alvin Bruney
    > >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > >> Got tidbits? Get it here... http://tinyurl.com/27cok
    > >> "Marek" <> wrote in message
    > >> news:wvinc.550$...
    > >> > Hi,
    > >> >
    > >> > Is Application_OnStart event hadler guaranteed to finish its

    execution
    > >> > before another HttpApplication object is brought into life?
    > >> >
    > >> > Marek
    > >> >
    > >> >
    > >>
    > >>
    > >>
    > >>

    > >
    > >

    >
    >
    Marek, May 10, 2004
    #5
  6. Marek

    DalePres Guest

    The solution to the problem is to lock the application object early in the
    code of your Application_OnStart with a call to Application.Lock(). This
    will make sure that any other calls are blocked until you complete your
    initialization.

    Dale

    "Marek" <> wrote in message
    news:V3vnc.619$%...
    > Hi Alvin,
    >
    > Thank you for your explanation. Still, I don't understand something.
    > Application_OnStart event is raised only ONCE on the first instance of
    > HttpApplication. Right?
    > I saw many examples of code where they perform some global initialization

    in
    > this handler
    > (such as reading config files, remote configuration to name a few).

    However,
    > I didn't see any prevention against
    > other HttpApplication instaces access the results of configuration BEFORE
    > Application_OnStart event
    > handler ends its execution. So I came to the question I asked. Could you
    > explain where I'm making
    > a mistake?
    >
    > Marek
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:...
    > > No such guarantee is made. I think there is some confusion in the

    question
    > > as well.
    > >
    > > The application_onstart event handler is an event which fires when a

    > request
    > > is paired with an httpapplication instance. The guarantee is only that

    > this
    > > request will be associated with this one httpapplication instance, that

    > is,
    > > sequential processing thru the http pipeline until the request is

    serviced
    > > fully by that specific httpapplication instance. Each request/instance

    > pair
    > > is handled on any available thread from the threadpool. The pairing

    > process
    > > is not
    > > sequential.
    > >
    > > The responsibility of pairing falls to the httpruntime object. The
    > > httpruntime object can handle many simultaneous concurrent
    > > requests - limited only by the available threads in the threadpool
    > > responsible for servicing requests. In this case, each request gets

    paired
    > > with an httpapplication instance. If the httpruntime could only respond

    to
    > > one request at a time, this would create a bottleneck under load. Once a
    > > request has been received, there is an implicit guarantee that the

    request
    > > can be associated with only one httpapplciation object.
    > >
    > >
    > >
    > > --
    > > Regards,
    > > Alvin Bruney
    > > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > > Got tidbits? Get it here... http://tinyurl.com/27cok
    > > "Marek" <> wrote in message
    > > news:wvinc.550$...
    > > > Hi,
    > > >
    > > > Is Application_OnStart event hadler guaranteed to finish its execution
    > > > before another HttpApplication object is brought into life?
    > > >
    > > > Marek
    > > >
    > > >

    > >
    > >
    > >
    > >

    >
    >
    DalePres, May 10, 2004
    #6
  7. Marek

    DalePres Guest

    Application.Init will be called for each instance of the application which
    approximately equals the maximum number of simultaneous requests since an
    application instance handles one request at a time. Application_OnStart
    will be called only once when the first instance of the application is
    called.

    Dale

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:...
    > The framework guarantees that, regardless of concurrent requests, the
    > application object will be initialized only once per application domain.
    > This happens when the first request is received. If two requests are
    > received at the same time, the runtime uses a spin-lock to force one

    request
    > to wait while the other is serviced guaranteeing threadsafety.
    >
    > Now, once that initialization has occurred, its an open field where thread
    > access/concurrency is concerned so care must be taken for objects with
    > global scope in the application object. Good question. I had to think

    about
    > this for a while.
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Marek" <> wrote in message
    > news:V3vnc.619$%...
    > > Hi Alvin,
    > >
    > > Thank you for your explanation. Still, I don't understand something.
    > > Application_OnStart event is raised only ONCE on the first instance of
    > > HttpApplication. Right?
    > > I saw many examples of code where they perform some global

    initialization
    > > in
    > > this handler
    > > (such as reading config files, remote configuration to name a few).
    > > However,
    > > I didn't see any prevention against
    > > other HttpApplication instaces access the results of configuration

    BEFORE
    > > Application_OnStart event
    > > handler ends its execution. So I came to the question I asked. Could you
    > > explain where I'm making
    > > a mistake?
    > >
    > > Marek
    > >
    > > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > > news:...
    > >> No such guarantee is made. I think there is some confusion in the
    > >> question
    > >> as well.
    > >>
    > >> The application_onstart event handler is an event which fires when a

    > > request
    > >> is paired with an httpapplication instance. The guarantee is only that

    > > this
    > >> request will be associated with this one httpapplication instance, that

    > > is,
    > >> sequential processing thru the http pipeline until the request is
    > >> serviced
    > >> fully by that specific httpapplication instance. Each request/instance

    > > pair
    > >> is handled on any available thread from the threadpool. The pairing

    > > process
    > >> is not
    > >> sequential.
    > >>
    > >> The responsibility of pairing falls to the httpruntime object. The
    > >> httpruntime object can handle many simultaneous concurrent
    > >> requests - limited only by the available threads in the threadpool
    > >> responsible for servicing requests. In this case, each request gets
    > >> paired
    > >> with an httpapplication instance. If the httpruntime could only respond
    > >> to
    > >> one request at a time, this would create a bottleneck under load. Once

    a
    > >> request has been received, there is an implicit guarantee that the
    > >> request
    > >> can be associated with only one httpapplciation object.
    > >>
    > >>
    > >>
    > >> --
    > >> Regards,
    > >> Alvin Bruney
    > >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > >> Got tidbits? Get it here... http://tinyurl.com/27cok
    > >> "Marek" <> wrote in message
    > >> news:wvinc.550$...
    > >> > Hi,
    > >> >
    > >> > Is Application_OnStart event hadler guaranteed to finish its

    execution
    > >> > before another HttpApplication object is brought into life?
    > >> >
    > >> > Marek
    > >> >
    > >> >
    > >>
    > >>
    > >>
    > >>

    > >
    > >

    >
    >
    DalePres, May 10, 2004
    #7
  8. Dino Esposito's book is about as good as it gets on ASP.NET. This book is
    not about examples and snippets of code, it's about theory and how things
    work underneath the hood.

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Marek" <> wrote in message
    news:xDAnc.602$...
    > Thank you. Where could I read more about it?
    >
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:...
    >> The framework guarantees that, regardless of concurrent requests, the
    >> application object will be initialized only once per application domain.
    >> This happens when the first request is received. If two requests are
    >> received at the same time, the runtime uses a spin-lock to force one

    > request
    >> to wait while the other is serviced guaranteeing threadsafety.
    >>
    >> Now, once that initialization has occurred, its an open field where
    >> thread
    >> access/concurrency is concerned so care must be taken for objects with
    >> global scope in the application object. Good question. I had to think

    > about
    >> this for a while.
    >>
    >> --
    >> Regards,
    >> Alvin Bruney
    >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    >> Got tidbits? Get it here... http://tinyurl.com/27cok
    >> "Marek" <> wrote in message
    >> news:V3vnc.619$%...
    >> > Hi Alvin,
    >> >
    >> > Thank you for your explanation. Still, I don't understand something.
    >> > Application_OnStart event is raised only ONCE on the first instance of
    >> > HttpApplication. Right?
    >> > I saw many examples of code where they perform some global

    > initialization
    >> > in
    >> > this handler
    >> > (such as reading config files, remote configuration to name a few).
    >> > However,
    >> > I didn't see any prevention against
    >> > other HttpApplication instaces access the results of configuration

    > BEFORE
    >> > Application_OnStart event
    >> > handler ends its execution. So I came to the question I asked. Could
    >> > you
    >> > explain where I'm making
    >> > a mistake?
    >> >
    >> > Marek
    >> >
    >> > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    >> > news:...
    >> >> No such guarantee is made. I think there is some confusion in the
    >> >> question
    >> >> as well.
    >> >>
    >> >> The application_onstart event handler is an event which fires when a
    >> > request
    >> >> is paired with an httpapplication instance. The guarantee is only that
    >> > this
    >> >> request will be associated with this one httpapplication instance,
    >> >> that
    >> > is,
    >> >> sequential processing thru the http pipeline until the request is
    >> >> serviced
    >> >> fully by that specific httpapplication instance. Each request/instance
    >> > pair
    >> >> is handled on any available thread from the threadpool. The pairing
    >> > process
    >> >> is not
    >> >> sequential.
    >> >>
    >> >> The responsibility of pairing falls to the httpruntime object. The
    >> >> httpruntime object can handle many simultaneous concurrent
    >> >> requests - limited only by the available threads in the threadpool
    >> >> responsible for servicing requests. In this case, each request gets
    >> >> paired
    >> >> with an httpapplication instance. If the httpruntime could only
    >> >> respond
    >> >> to
    >> >> one request at a time, this would create a bottleneck under load. Once

    > a
    >> >> request has been received, there is an implicit guarantee that the
    >> >> request
    >> >> can be associated with only one httpapplciation object.
    >> >>
    >> >>
    >> >>
    >> >> --
    >> >> Regards,
    >> >> Alvin Bruney
    >> >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    >> >> Got tidbits? Get it here... http://tinyurl.com/27cok
    >> >> "Marek" <> wrote in message
    >> >> news:wvinc.550$...
    >> >> > Hi,
    >> >> >
    >> >> > Is Application_OnStart event hadler guaranteed to finish its

    > execution
    >> >> > before another HttpApplication object is brought into life?
    >> >> >
    >> >> > Marek
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Alvin Bruney [MVP], May 10, 2004
    #8
  9. Marek

    Scott Allen Guest

    This locks the Application state object, which doesn't block any other
    requests unless they are trying to lock the Application object also.

    --
    Scott
    http://www.OdeToCode.com

    On Sun, 9 May 2004 20:51:03 -0500, "DalePres" <>
    wrote:

    >The solution to the problem is to lock the application object early in the
    >code of your Application_OnStart with a call to Application.Lock(). This
    >will make sure that any other calls are blocked until you complete your
    >initialization.
    >
    >Dale
    >
    >"Marek" <> wrote in message
    >news:V3vnc.619$%...
    >> Hi Alvin,
    >>
    >> Thank you for your explanation. Still, I don't understand something.
    >> Application_OnStart event is raised only ONCE on the first instance of
    >> HttpApplication. Right?
    >> I saw many examples of code where they perform some global initialization

    >in
    >> this handler
    >> (such as reading config files, remote configuration to name a few).

    >However,
    >> I didn't see any prevention against
    >> other HttpApplication instaces access the results of configuration BEFORE
    >> Application_OnStart event
    >> handler ends its execution. So I came to the question I asked. Could you
    >> explain where I'm making
    >> a mistake?
    >>
    >> Marek
    >>
    >> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    >> news:...
    >> > No such guarantee is made. I think there is some confusion in the

    >question
    >> > as well.
    >> >
    >> > The application_onstart event handler is an event which fires when a

    >> request
    >> > is paired with an httpapplication instance. The guarantee is only that

    >> this
    >> > request will be associated with this one httpapplication instance, that

    >> is,
    >> > sequential processing thru the http pipeline until the request is

    >serviced
    >> > fully by that specific httpapplication instance. Each request/instance

    >> pair
    >> > is handled on any available thread from the threadpool. The pairing

    >> process
    >> > is not
    >> > sequential.
    >> >
    >> > The responsibility of pairing falls to the httpruntime object. The
    >> > httpruntime object can handle many simultaneous concurrent
    >> > requests - limited only by the available threads in the threadpool
    >> > responsible for servicing requests. In this case, each request gets

    >paired
    >> > with an httpapplication instance. If the httpruntime could only respond

    >to
    >> > one request at a time, this would create a bottleneck under load. Once a
    >> > request has been received, there is an implicit guarantee that the

    >request
    >> > can be associated with only one httpapplciation object.
    >> >
    >> >
    >> >
    >> > --
    >> > Regards,
    >> > Alvin Bruney
    >> > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    >> > Got tidbits? Get it here... http://tinyurl.com/27cok
    >> > "Marek" <> wrote in message
    >> > news:wvinc.550$...
    >> > > Hi,
    >> > >
    >> > > Is Application_OnStart event hadler guaranteed to finish its execution
    >> > > before another HttpApplication object is brought into life?
    >> > >
    >> > > Marek
    >> > >
    >> > >
    >> >
    >> >
    >> >
    >> >

    >>
    >>

    >
    Scott Allen, May 11, 2004
    #9
    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. yop
    Replies:
    4
    Views:
    423
  2. Shiv Kumar

    Global - Application_OnStart question

    Shiv Kumar, Jan 13, 2004, in forum: ASP .Net
    Replies:
    19
    Views:
    732
    Shiv Kumar
    Jan 14, 2004
  3. =?Utf-8?B?QmlsbCBIZWNrbGU=?=

    Application_OnStart

    =?Utf-8?B?QmlsbCBIZWNrbGU=?=, Aug 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    323
    =?Utf-8?B?QnJhZCBRdWlubg==?=
    Aug 16, 2004
  4. archana
    Replies:
    1
    Views:
    331
  5. Bren
    Replies:
    3
    Views:
    93
Loading...

Share This Page