By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,205 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,205 IT Pros & Developers. It's quick & easy.

Is access to the Session thread-safe?

P: n/a
When accessing, for example, an object stored in the session such as:

Session[ "MyObject" ].MyProperty = "Some Value";

Is access to MyObject thread-safe?
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Chris:

Here are some details:

ASP.NET does manage access to session state with a ReaderWriterLock.
The default is to take a writer lock, which serializes requests coming
in on the same session (using EnableSessionState="ReadOnly" takes a
reader lock and does allow concurrent request processing on a
session).

In this example, you are not really modifying session state, but
modifying an object through a reference stored in session state. If
anyone else has a reference to the same object the code is only thread
safe if MyObject is thread safe.

Know what I mean?

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
<CA*****************@hotmail.com> wrote:
When accessing, for example, an object stored in the session such as:

Session[ "MyObject" ].MyProperty = "Some Value";

Is access to MyObject thread-safe?


Nov 19 '05 #2

P: n/a
Yeah, makes perfect sense.

Could you possibly elaborate a little more on exactly when ASP.NET creates
and releases the ReaderWriter Lock?
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:om********************************@4ax.com...
Hi Chris:

Here are some details:

ASP.NET does manage access to session state with a ReaderWriterLock.
The default is to take a writer lock, which serializes requests coming
in on the same session (using EnableSessionState="ReadOnly" takes a
reader lock and does allow concurrent request processing on a
session).

In this example, you are not really modifying session state, but
modifying an object through a reference stored in session state. If
anyone else has a reference to the same object the code is only thread
safe if MyObject is thread safe.

Know what I mean?

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
<CA*****************@hotmail.com> wrote:
When accessing, for example, an object stored in the session such as:

Session[ "MyObject" ].MyProperty = "Some Value";

Is access to MyObject thread-safe?

Nov 19 '05 #3

P: n/a
When the SessionStateModule catches the AcquireRequestState event
during request processing. This happens before control reaches the
ASPX page handler.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
<CA*****************@hotmail.com> wrote:
Yeah, makes perfect sense.

Could you possibly elaborate a little more on exactly when ASP.NET creates
and releases the ReaderWriter Lock?


Nov 19 '05 #4

P: n/a
Thanks Scott, very helpful//

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:48********************************@4ax.com...
When the SessionStateModule catches the AcquireRequestState event
during request processing. This happens before control reaches the
ASPX page handler.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
<CA*****************@hotmail.com> wrote:
Yeah, makes perfect sense.

Could you possibly elaborate a little more on exactly when ASP.NET createsand releases the ReaderWriter Lock?

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.