473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Accessing session from thread

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
Nov 25 '05 #1
2 2605
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" <js************@ecclesdeletethiscollege.ac.uk> wrote in message
news:uL*************@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

Nov 25 '05 #2
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
"John Timney ( MVP )" <ti*****@despammed.com> wrote in message
news:er**************@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" <js************@ecclesdeletethiscollege.ac.uk> wrote in message
news:uL*************@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


Nov 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: ndsoumah | last post by:
hello guys I'm trying to get access to variables I put in a session variable from another page and it fails... here's the exact situation main file page1.php
1
by: Philip Townsend | last post by:
How would one go about accessing the Session object from a cs class file? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
by: Bruce W.1 | last post by:
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.
0
by: matt | last post by:
I've come across a real problem and am totally stuck as to why this is happening, hoping desperately that someone else has experienced the same thing, and knows a solution! Session state should be...
4
by: Chris Newby | last post by:
When accessing, for example, an object stored in the session such as: Session.MyProperty = "Some Value"; Is access to MyObject thread-safe?
3
by: Michael | last post by:
Hi, If I use SQL Server to store session state, whenever I call Session is there a call to SQL Server? Even if I call Session a few times in the same Web page, or even the same code block? ...
1
by: JEB | last post by:
I know that with Web Services, you should be doing everything in a stateless environment. However, I have three methods out of over 100 that need state. I have the client cookie container,...
5
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the...
5
by: Mythran | last post by:
I've read some documentation about accessing objects created in other threads and the code below is similar to what I've gathered for what I have to do: private delegate void...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.