Alvin is correct, of course, but let me add something just in case: if your
other part of the HttpContext object from a separate thread. That's the
what's in the context...
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:ucHjaDfMEHA.2592@tk2msftngp13.phx.gbl...
> >When the process running on the new thread reaches the reference to the
> > >HttpContext.Current.Cache object in the static method I get a runtime
> > >exception saying "Object reference not set to an instance of an
object."
>
> You will need to pass a reference to the httpcontext to the thread. That's
> the only way this will work because the thread is not allowed to
manipulate
> the context object since it belongs to the main thread.
>
> >Educated guess: I'm thinking I need to establish the context of the new
> > >thread to be the same as that of the web page which spawns the thread.
> > >Am I headed in the right general direction? Can anyone offer any
specific
> > >example or explanation of how to implement multi-threading with access
>to
> >the web application cache?
>
> yup, something like that. The way you establish context is by passing in a
> reference to child thread from the main thread. You can do this in your
> thread class constructor
>
> public class thread
> {
> public start(HttpConstext current)....
>
> the call would be something like thread t = new
thread(HttpContext.Current)
>
> --
> Regards,
> Alvin Bruney
> [ASP.NET MVP
http://mvp.support.microsoft.com/default.aspx]
> Got tidbits? Get it here...
http://tinyurl.com/27cok > "Ken Everett" <keverett@troygroup.com> wrote in message
> news:BB404153-134C-4E2B-A57D-E5F24ADADECE@microsoft.com...
> >I have a web page that executes a potentially lengthy method declared on
an
> >object in a referenced assembly.
> >
> > Nested within this method is a call to a static method which retrieves
> > values from cache via the HttpContext.Current.Cache object.
> >
> > In order to make the web application more responsive, I am now trying to
> > execute this long running method in a new thread.
> >
> > My problem: When the process running on the new thread reaches the
> > reference to the HttpContext.Current.Cache object in the static method I
> > get a runtime exception saying "Object reference not set to an instance
of
> > an object.".
> >
> > Educated guess: I'm thinking I need to establish the context of the new
> > thread to be the same as that of the web page which spawns the thread.
Am
> > I headed in the right general direction? Can anyone offer any specific
> > example or explanation of how to implement multi-threading with access
to
> > the web application cache?
>
>