![]() |
|
|
|||||||
![]() |
ASP Net - Is access to the Session thread-safe? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
When accessing, for example, an object stored in the session such as:
Session[ "MyObject" ].MyProperty = "Some Value"; Is access to MyObject thread-safe? Chris Newby |
|
|
|
|
#2 |
|
Posts: 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" <> wrote: > When accessing, for example, an object stored in the session such as: > >Session[ "MyObject" ].MyProperty = "Some Value"; > >Is access to MyObject thread-safe? > |
|
|
|
#3 |
|
Posts: 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" <> wrote in message news > 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" > <> wrote: > > > When accessing, for example, an object stored in the session such as: > > > >Session[ "MyObject" ].MyProperty = "Some Value"; > > > >Is access to MyObject thread-safe? > > > |
|
|
|
#4 |
|
Posts: 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" <> wrote: >Yeah, makes perfect sense. > >Could you possibly elaborate a little more on exactly when ASP.NET creates >and releases the ReaderWriter Lock? > > |
|
|
|
#5 |
|
Posts: n/a
|
Thanks Scott, very helpful//
"Scott Allen" <> wrote in message news:... > 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" > <> wrote: > > >Yeah, makes perfect sense. > > > >Could you possibly elaborate a little more on exactly when ASP.NET creates > >and releases the ReaderWriter Lock? > > > > > |
|