PC Review


Reply
Thread Tools Rate Thread

access web application object from background thread?

 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      8th Feb 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      8th Feb 2007
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

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




"Mike" wrote:

> 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

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      8th Feb 2007
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

"Peter Bromberg [C# MVP]" wrote:
> 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
>
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net


 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      8th Feb 2007
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/arch...06/437559.aspx

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

Mike

"Mike" wrote:

> 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
>
> "Peter Bromberg [C# MVP]" wrote:
> > 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
> >
> > --
> > Site: http://www.eggheadcafe.com
> > UnBlog: http://petesbloggerama.blogspot.com
> > Short urls & more: http://ittyurl.net

>

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      9th Feb 2007
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" wrote:

> 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/arch...06/437559.aspx
>
> Thank you Peter Bromberg. You are a Rock Star, I have benefitted a lot from
> your various articles/postings.
>
> Mike
>
> "Mike" wrote:
>
> > 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
> >
> > "Peter Bromberg [C# MVP]" wrote:
> > > 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
> > >
> > > --
> > > Site: http://www.eggheadcafe.com
> > > UnBlog: http://petesbloggerama.blogspot.com
> > > Short urls & more: http://ittyurl.net

> >

 
Reply With Quote
 
Mike Otten
Guest
Posts: n/a
 
      9th Feb 2007
I'll bet you slouch too. Man, if I can't get in a good slouch: *nap*.

Peter Bromberg [C# MVP] wrote:
> Glad you fixed it. Rock star, doubt it. Just another slob trying to help out
> by giving back.
> Cheers,
> Peter
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Start background thread when a UI button is clicked, and Update UIbutton from background thread Curious Microsoft Dot NET 0 31st Mar 2010 10:01 PM
Re: Object Pooling in Background Thread 3.5 Sample? Gregory A. Beamer Microsoft Dot NET Framework 2 22nd Oct 2009 04:17 PM
Re: Object Pooling in Background Thread 3.5 Sample? Peter Duniho Microsoft Dot NET Framework 0 14th Oct 2009 09:11 PM
launching background thread in asp.net web application. Ashish Microsoft ASP .NET 1 23rd Dec 2005 09:52 AM
Access Application Object From A Thread? Al Cohen Microsoft ASP .NET 4 10th Jan 2004 02:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 PM.