Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Is the code under App_code reentrant???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lander - 08 Mar 2008 02:36 GMT
That is, if multiple users are requesting or posting to the same page,
is the the code under app_code reentrant??? Why?

Thanks~!
Anthony Jones - 08 Mar 2008 12:44 GMT
> 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.

Signature

Anthony Jones - MVP ASP/ASP.NET

lander - 09 Mar 2008 06:58 GMT
> > That is, if multiple users are requesting or posting to the same page,
> > is the the code under app_code reentrant??? Why?
[quoted text clipped - 11 lines]
> --
> 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?
Anthony Jones - 09 Mar 2008 15:31 GMT
>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.

Signature

Anthony Jones - MVP ASP/ASP.NET

lander - 10 Mar 2008 04:18 GMT
> >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?
[quoted text clipped - 24 lines]
> --
> Anthony Jones - MVP ASP/ASP.NET

Thanks very much!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.