Thread accessing session variables?

B

Bruce W.1

I need to spin of a thread that periodically checks the Application
state. How can a thread access Application or Session states? Send it
the httpContext?

Thanks for your help.
 
A

Alvin Bruney [MVP]

The httpcontext is owned by the main thread so you will need to send in a
reference to the object to the thread. Here is an example:
function(System.Web.HttpContext Stream)

{
Stream.Response.Write("vlah");
}
call it like so
function(HttpContext.Current);
 
K

Kevin Spencer

I don't think this will work. If the thread is running separately from the
main Page execution thread, the Page may have already been processed, in
which case the Response and Request would not be available.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Alvin Bruney said:
The httpcontext is owned by the main thread so you will need to send in a
reference to the object to the thread. Here is an example:
function(System.Web.HttpContext Stream)

{
Stream.Response.Write("vlah");
}
call it like so
function(HttpContext.Current);

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Bruce W.1 said:
I need to spin of a thread that periodically checks the Application
state. How can a thread access Application or Session states? Send it
the httpContext?

Thanks for your help.
 
A

Alvin Bruney [MVP]

Right. I didn't consider that context. In that case the main thread would
need to wait on the worker thread to be finished.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Kevin Spencer said:
I don't think this will work. If the thread is running separately from the
main Page execution thread, the Page may have already been processed, in
which case the Response and Request would not be available.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Alvin Bruney said:
The httpcontext is owned by the main thread so you will need to send in a
reference to the object to the thread. Here is an example:
function(System.Web.HttpContext Stream)

{
Stream.Response.Write("vlah");
}
call it like so
function(HttpContext.Current);

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Bruce W.1 said:
I need to spin of a thread that periodically checks the Application
state. How can a thread access Application or Session states? Send it
the httpContext?

Thanks for your help.
 
K

Kevin Spencer

Right. I didn't consider that context. In that case the main thread would
need to wait on the worker thread to be finished.

That would do it. However, it would most probably also eliminate the benefit
that the poster was trying to obtain by using a separate thread. Possibly
not.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Alvin Bruney said:
Right. I didn't consider that context. In that case the main thread would
need to wait on the worker thread to be finished.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Kevin Spencer said:
I don't think this will work. If the thread is running separately from the
main Page execution thread, the Page may have already been processed, in
which case the Response and Request would not be available.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
in
a
reference to the object to the thread. Here is an example:
function(System.Web.HttpContext Stream)

{
Stream.Response.Write("vlah");
}
call it like so
function(HttpContext.Current);

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
I need to spin of a thread that periodically checks the Application
state. How can a thread access Application or Session states? Send it
the httpContext?

Thanks for your help.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top