PC Review


Reply
Thread Tools Rate Thread

Is the code under App_code reentrant???

 
 
lander
Guest
Posts: n/a
 
      8th Mar 2008
That is, if multiple users are requesting or posting to the same page,
is the the code under app_code reentrant??? Why?

Thanks~!
 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      8th Mar 2008
"lander" <(E-Mail Removed)> wrote in message
news:cbc61d9b-32b4-4a81-a7ab-(E-Mail Removed)...
> That is, if multiple users are requesting or posting to the same page,
> is the the code under app_code reentrant??? Why?
>


I'm not sure you are using the term re-entrant appropriately I suspect you
mean is it threadsafe. The answer is: its up to you.

Normally classes that you may place in app_code that are then instanced by
ASPX pages will be threadsafe in that they are only being used by one thread
for the duration of the current request processing. However if you then
place instances such classes somewhere that can be accessed by more than one
thread (cache, static member etc) the responsibility for creating thread
safety is yours.


--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
lander
Guest
Posts: n/a
 
      9th Mar 2008
On 3月8日, 下午8时44分, "Anthony Jones" <A...@yadayadayada.com> wrote:
> "lander" <lostlander....@gmail.com> wrote in message
>
> news:cbc61d9b-32b4-4a81-a7ab-(E-Mail Removed)...
>
> > That is, if multiple users are requesting or posting to the same page,
> > is the the code under app_code reentrant??? Why?

>
> I'm not sure you are using the term re-entrant appropriately I suspect you
> mean is it threadsafe. The answer is: its up to you.
>
> Normally classes that you may place in app_code that are then instanced by
> ASPX pages will be threadsafe in that they are only being used by one thread
> for the duration of the current request processing. However if you then
> place instances such classes somewhere that can be accessed by more than one
> thread (cache, static member etc) the responsibility for creating thread
> safety is yours.
>
> --
> Anthony Jones - MVP ASP/ASP.NET


Ok, i create one variable inside the page class, which is static and
its value is set in page_load, is it safe to do so?
 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      9th Mar 2008
"lander" <(E-Mail Removed)> wrote in message
news:78e2b82f-6517-4482-bc5f-(E-Mail Removed)...
>Ok, i create one variable inside the page class, which is static and
>its value is set in page_load, is it safe to do so?


No.

Static variables will be available across the whole app domain. It is
conceivable that two clients hitting the same page at the same time would
have two threads trying to modify that variable at the same time.

You will need to add some synchronising code such as:-

static SomeType ourValue = null;
static readonly object ourLock = new object();

public static void ValueMutator()
{
lock(ourLock);
{
// code that modified ourValue;
}
}

Of course the exact nature of the locking needed (if any) will depend on the
page logic.

--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
lander
Guest
Posts: n/a
 
      10th Mar 2008
On 3月9日, 下午10时31分, "Anthony Jones" <A...@yadayadayada.com> wrote:
> "lander" <lostlander....@gmail.com> wrote in message
>
> news:78e2b82f-6517-4482-bc5f-(E-Mail Removed)...
>
> >Ok, i create one variable inside the page class, which is static and
> >its value is set in page_load, is it safe to do so?

>
> No.
>
> Static variables will be available across the whole app domain. It is
> conceivable that two clients hitting the same page at the same time would
> have two threads trying to modify that variable at the same time.
>
> You will need to add some synchronising code such as:-
>
> static SomeType ourValue = null;
> static readonly object ourLock = new object();
>
> public static void ValueMutator()
> {
> lock(ourLock);
> {
> // code that modified ourValue;
> }
>
> }
>
> Of course the exact nature of the locking needed (if any) will depend on the
> page logic.
>
> --
> Anthony Jones - MVP ASP/ASP.NET


Thanks very much!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
First time at using shared code in App_Code directory bissatch@yahoo.co.uk Microsoft ASP .NET 3 18th Feb 2007 08:46 AM
Is it a good idea to put all code-behind in App_Code folder? =?Utf-8?B?d2FsdGVy?= Microsoft ASP .NET 2 2nd Mar 2006 08:53 PM
Can VB code access C# methods w/in same App_Code? =?Utf-8?B?TWlrZSBLLg==?= Microsoft C# .NET 0 30th Jan 2006 02:48 PM
debugger wont step into app_code folder based code Brian Henry Microsoft ASP .NET 0 7th Nov 2005 02:50 PM
Reentrant (?) Console Application.... carlbono@gmail.com Microsoft C# .NET 14 23rd Aug 2005 06:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 AM.