Home All Groups Group Topic Archive Search About

Accessing session from thread

Author
25 Nov 2005 7:07 PM
John
Is there a safe way to gain access to the session object from inside a
spawned thread, in ASP.NET?

I'm familiar with the principle of creating a data storage object, passing a
reference to the thread, and then adding the object to the session. But this
won't work when using StateServer because of serialization (session only
contains a snapshop of the object at the point I added it, and the changes
made by the thread occur elsewhere).

Ideally I'd like:

void MyThreadWorker()
{
  HttpSession sess = somemagicroutine();
  sess["counter"] = 1;
}

Thanks,

John

Author
25 Nov 2005 8:07 PM
John Timney ( MVP )
As long as the pipeline is still active, then the context of the session may
be available, but its always a risky thing to rely on, and you might be
better taking a snapshot of session items into a collection at thread start
and passing that to the thread, rather than maintaining access to the live
session.

Read this for a pointer:

http://www.odetocode.com/Articles/112.aspx

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

Show quoteHide quote
"John" <jsparrowNOSPAM@ecclesdeletethiscollege.ac.uk> wrote in message
news:uLLhtNf8FHA.956@TK2MSFTNGP10.phx.gbl...
> Is there a safe way to gain access to the session object from inside a
> spawned thread, in ASP.NET?
>
> I'm familiar with the principle of creating a data storage object, passing
> a reference to the thread, and then adding the object to the session. But
> this won't work when using StateServer because of serialization (session
> only contains a snapshop of the object at the point I added it, and the
> changes made by the thread occur elsewhere).
>
> Ideally I'd like:
>
> void MyThreadWorker()
> {
>  HttpSession sess = somemagicroutine();
>  sess["counter"] = 1;
> }
>
> Thanks,
>
> John
>
Are all your drivers up to date? click for free checkup

Author
26 Nov 2005 4:02 PM
John
Thanks John,

But a snapshot won't allow me to signal things from inside the worker thread
to the main threads (other aspx pages). For me the problem is outgoing
information, not incomming.

The only strategy I can see is to use the database - which seems a bit
over-powered for the job!

John


Show quoteHide quote
"John Timney ( MVP )" <timneyj@despammed.com> wrote in message
news:erg07uf8FHA.3544@TK2MSFTNGP09.phx.gbl...
> As long as the pipeline is still active, then the context of the session
> may be available, but its always a risky thing to rely on, and you might
> be better taking a snapshot of session items into a collection at thread
> start and passing that to the thread, rather than maintaining access to
> the live session.
>
> Read this for a pointer:
>
> http://www.odetocode.com/Articles/112.aspx
>
> --
> Regards
>
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
>
> "John" <jsparrowNOSPAM@ecclesdeletethiscollege.ac.uk> wrote in message
> news:uLLhtNf8FHA.956@TK2MSFTNGP10.phx.gbl...
>> Is there a safe way to gain access to the session object from inside a
>> spawned thread, in ASP.NET?
>>
>> I'm familiar with the principle of creating a data storage object,
>> passing a reference to the thread, and then adding the object to the
>> session. But this won't work when using StateServer because of
>> serialization (session only contains a snapshop of the object at the
>> point I added it, and the changes made by the thread occur elsewhere).
>>
>> Ideally I'd like:
>>
>> void MyThreadWorker()
>> {
>>  HttpSession sess = somemagicroutine();
>>  sess["counter"] = 1;
>> }
>>
>> Thanks,
>>
>> John
>>
>
>

Bookmark and Share