access web application object from background thread?

G

Guest

I have an asp.net 2.0 web application where some of the processing has been
delegated to a background worker thread. The code for that thread is in a VB
module that is part of the application, but is not a code-behind. I would
like to read/write values in the application object's cache, but can't find a
way to get to it. The background thread is part of the web app, but it does
not run in the context of an http request. So when I try:
Dim app As HttpApplication = HttpContext.Current.ApplicationInstance
Dim appcache As HttpApplicationState = app.Application
appcache.Add("v1", 1)
I get an exception on the first line because "Current' is set to nothing.

Any suggestions appreciated-

Mike
 
G

Guest

Your VB module that needs to access the current HttpContext would need to
have a reference to System.Web assembly.
There may be other issues but since we haven't seen your code, deal with
those afterward.
Peter
 
G

Guest

My apologies Peter, but I can't figure out where to go with your advice.
Maybe I misused the term 'module'? It's just another VB file in my web app
project, that isn't a code-behind for an aspx page. I'm only guessing that
that's why HttpContext.Current is coming up null. Or is it because the code
actually runs in a background thread, and not associated directly or
indirectly with http request code?

In any event, my project has a reference to System.Web, and I do not see a
way to add a reference to System.Web just for this one VB file.

Thanks for your input, apologies if I am making this harder than it should be.

Mike
 
G

Guest

OK, this should have been obvious: There is no HttpContext.Current when my
background thread is running an no http requests are active. Duh.

Switched to HttpRuntime.Cache, and all good. Here's an article if anyone
follows this thread looking for help:

http://weblogs.asp.net/pjohnson/archive/2006/02/06/437559.aspx

Thank you Peter Bromberg. You are a Rock Star, I have benefitted a lot from
your various articles/postings.

Mike

Mike said:
My apologies Peter, but I can't figure out where to go with your advice.
Maybe I misused the term 'module'? It's just another VB file in my web app
project, that isn't a code-behind for an aspx page. I'm only guessing that
that's why HttpContext.Current is coming up null. Or is it because the code
actually runs in a background thread, and not associated directly or
indirectly with http request code?

In any event, my project has a reference to System.Web, and I do not see a
way to add a reference to System.Web just for this one VB file.

Thanks for your input, apologies if I am making this harder than it should be.

Mike
 
G

Guest

Glad you fixed it. Rock star, doubt it. Just another slob trying to help out
by giving back.
Cheers,
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Mike said:
OK, this should have been obvious: There is no HttpContext.Current when my
background thread is running an no http requests are active. Duh.

Switched to HttpRuntime.Cache, and all good. Here's an article if anyone
follows this thread looking for help:

http://weblogs.asp.net/pjohnson/archive/2006/02/06/437559.aspx

Thank you Peter Bromberg. You are a Rock Star, I have benefitted a lot from
your various articles/postings.

Mike
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top