Access Application Object From A Thread?

A

Al Cohen

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
 
H

Hermit Dave

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...
 
A

Al Cohen

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
 
A

Al Cohen

Aha! Problem solved!

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

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top