Access Application Object From A Thread?

Discussion in 'ASP .Net' started by Al Cohen, Jan 9, 2004.

  1. Al Cohen

    Al Cohen Guest

    We've got a few methods that take a long time to complete. We're in the
    process of starting to launch these as separate threads, and having the
    web form refresh every few seconds to report the method's progress.
    Communication between "new" thread and web page is via the Session
    object. (Not rocket science so far.)

    The first problem that we ran into was that our methods could not see
    the Session object anymore once they were placed in a seperate thread.
    After Googling for a fix, we remedied this by passing a Session
    reference to the methods that we need to use. This was somewhat of a
    pain as we had to rewrite a library to take the Session reference as a
    parameter. But it works.

    Now we're finding that we also cannot see the Application object from
    our newly-threaded methods. I suppose that we could pass a reference to
    the Application object whenever it's needed, but this will be pretty
    painful in terms of rewriting code - we have a lot of stuff cached in
    the Application object.

    So, my question: is there some other way that we can access the
    Application from our threads that is more elegant than changing our
    libraries to require a reference to be explicitly passed?

    Thanks!

    Al Cohen
     
    Al Cohen, Jan 9, 2004
    #1
    1. Advertising

  2. Al Cohen

    Hermit Dave Guest

    System.Web.HttpContext.Current.Application should get you the application
    object from anywhere....
    System.Web.HttpContext.Current.System is also available..

    I had some issues getting the context but most people on the ng... just get
    it fine...

    --
    Regards,

    HD

    "Al Cohen" <-o-r-n-e-l-l.edu> wrote in message
    news:p...
    > We've got a few methods that take a long time to complete. We're in the
    > process of starting to launch these as separate threads, and having the
    > web form refresh every few seconds to report the method's progress.
    > Communication between "new" thread and web page is via the Session
    > object. (Not rocket science so far.)
    >
    > The first problem that we ran into was that our methods could not see
    > the Session object anymore once they were placed in a seperate thread.
    > After Googling for a fix, we remedied this by passing a Session
    > reference to the methods that we need to use. This was somewhat of a
    > pain as we had to rewrite a library to take the Session reference as a
    > parameter. But it works.
    >
    > Now we're finding that we also cannot see the Application object from
    > our newly-threaded methods. I suppose that we could pass a reference to
    > the Application object whenever it's needed, but this will be pretty
    > painful in terms of rewriting code - we have a lot of stuff cached in
    > the Application object.
    >
    > So, my question: is there some other way that we can access the
    > Application from our threads that is more elegant than changing our
    > libraries to require a reference to be explicitly passed?
    >
    > Thanks!
    >
    > Al Cohen
    >
     
    Hermit Dave, Jan 9, 2004
    #2
    1. Advertising

  3. Al Cohen

    Al Cohen Guest

    System.Web.HttpContext.Current.Application is exactly what we're
    doing... and it works fine from the main application thread, but returns
    null from any threads launched from the main application thread.

    At the risk of being stupid, what is
    System.Web.HttpContext.Current.System? I tried it, and Visual Studio
    and Google both get confused?

    Thanks,

    Al

    Hermit Dave wrote:

    > System.Web.HttpContext.Current.Application should get you the application
    > object from anywhere....
    > System.Web.HttpContext.Current.System is also available..
    >
    > I had some issues getting the context but most people on the ng... just get
    > it fine...
    >
     
    Al Cohen, Jan 9, 2004
    #3
  4. Al Cohen

    Hermit Dave Guest

    Sorry mate couldnt find any member call System in Context object...

    http://msdn.microsoft.com/library/d...tml/frlrfsystemwebhttpcontextmemberstopic.asp

    as for not getting session object as a part of secondary threads... never
    had to do that.... see what other say

    --
    Regards,

    HD

    "Al Cohen" <> wrote in message
    news:...
    > System.Web.HttpContext.Current.Application is exactly what we're
    > doing... and it works fine from the main application thread, but returns
    > null from any threads launched from the main application thread.
    >
    > At the risk of being stupid, what is
    > System.Web.HttpContext.Current.System? I tried it, and Visual Studio
    > and Google both get confused?
    >
    > Thanks,
    >
    > Al
    >
    > Hermit Dave wrote:
    >
    > > System.Web.HttpContext.Current.Application should get you the

    application
    > > object from anywhere....
    > > System.Web.HttpContext.Current.System is also available..
    > >
    > > I had some issues getting the context but most people on the ng... just

    get
    > > it fine...
    > >

    >
     
    Hermit Dave, Jan 9, 2004
    #4
  5. Al Cohen

    Al Cohen Guest

    Aha! Problem solved!

    Added a reference to the Application object in a static method: it's
    available from my threads.


    Al Cohen wrote:
    > We've got a few methods that take a long time to complete. We're in the
    > process of starting to launch these as separate threads, and having the
    > web form refresh every few seconds to report the method's progress.
    > Communication between "new" thread and web page is via the Session
    > object. (Not rocket science so far.)
    >
    > The first problem that we ran into was that our methods could not see
    > the Session object anymore once they were placed in a seperate thread.
    > After Googling for a fix, we remedied this by passing a Session
    > reference to the methods that we need to use. This was somewhat of a
    > pain as we had to rewrite a library to take the Session reference as a
    > parameter. But it works.
    >
    > Now we're finding that we also cannot see the Application object from
    > our newly-threaded methods. I suppose that we could pass a reference to
    > the Application object whenever it's needed, but this will be pretty
    > painful in terms of rewriting code - we have a lot of stuff cached in
    > the Application object.
    >
    > So, my question: is there some other way that we can access the
    > Application from our threads that is more elegant than changing our
    > libraries to require a reference to be explicitly passed?
    >
    > Thanks!
    >
    > Al Cohen
    >
     
    Al Cohen, Jan 10, 2004
    #5
    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. Sean
    Replies:
    2
    Views:
    520
  2. Johanna
    Replies:
    0
    Views:
    624
    Johanna
    Oct 13, 2004
  3. =?Utf-8?B?U3RlcGhhbmU=?=

    Is ArrayList in application object are thread safe?

    =?Utf-8?B?U3RlcGhhbmU=?=, Oct 4, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    5,384
    John Murray
    Oct 4, 2005
  4. =?Utf-8?B?TWlrZQ==?=

    access web application object from background thread?

    =?Utf-8?B?TWlrZQ==?=, Feb 8, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    510
    Mike Otten
    Feb 9, 2007
  5. Crouchez
    Replies:
    2
    Views:
    360
Loading...

Share This Page