Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Critical section in WebForms

Reply
Thread Tools

Critical section in WebForms

 
 
=?Utf-8?B?Q2hyaXN0aWFu?=
Guest
Posts: n/a
 
      10-07-2004
I have a class named AccessClass to access a legacy system.
In a webform i instanciate an AccessClass object named myAccess
and i call a method : myAccess.accessmethod()

I want to insure that no two webforms run simultaneouslly the code in
accessMethod()

So the code of accessMethode() is

void accessMethod()
{
lock(this)
{
... code ...
}
}

My questions are :
Is this insure my goal ? Is my code a critical section for all clients ?
I have a doubt because each webform has his proper instance of AccessClass.
If two webforms instanciate an AccessClass object and call AccessMethod() at
the same time, there is two different objects so if the critical section is
relative to the object there is no critical section among all clients.

If my solution is bad, an other idea is to pass a reference to the
"Application" object to myMethod and to use it as the lock parameter. Indeed
"Application" is shared between all clients.
Is it a better idea ?

If not, what is the solution ?

Thanks,

Christian


 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      10-07-2004
Hi Christian:

The way you describe the code then no, you are not getting exclusive
access to the system becauseeach client is locking on a different
instance.

You want the locks to be as private as possible. Locking on the
Application object can cause all sorts of problems, because anyone can
lock on the Application object.

My suggestion would be to add a private static object field to the
AccessClass and lock on that object. It's visible only inside the
AccessClass but being static, every client will lock on the same
object instance.

Just be very careful and test well, I'm sure you know additional
locks, particularly in long running calls can kill a web application.

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

On Thu, 7 Oct 2004 08:07:06 -0700, Christian
<> wrote:

>I have a class named AccessClass to access a legacy system.
>In a webform i instanciate an AccessClass object named myAccess
>and i call a method : myAccess.accessmethod()
>
>I want to insure that no two webforms run simultaneouslly the code in
>accessMethod()
>
>So the code of accessMethode() is
>
>void accessMethod()
>{
> lock(this)
> {
> ... code ...
> }
>}
>
>My questions are :
>Is this insure my goal ? Is my code a critical section for all clients ?
>I have a doubt because each webform has his proper instance of AccessClass.
>If two webforms instanciate an AccessClass object and call AccessMethod() at
>the same time, there is two different objects so if the critical section is
>relative to the object there is no critical section among all clients.
>
>If my solution is bad, an other idea is to pass a reference to the
>"Application" object to myMethod and to use it as the lock parameter. Indeed
>"Application" is shared between all clients.
>Is it a better idea ?
>
>If not, what is the solution ?
>
>Thanks,
>
>Christian
>


 
Reply With Quote
 
 
 
 
=?Utf-8?B?dG9tIHdpc25vd3NraQ==?=
Guest
Posts: n/a
 
      10-08-2004
You are using two different locks to lock the section therefor each thread
will be able to access the section. The reason for this is when each form
instantiates the AccessClass, they get their own instance of the obj. They
will then lock on thier own instance, defeating the purpose.
USE: lock(typeof(AccessClass))

"Christian" wrote:

> I have a class named AccessClass to access a legacy system.
> In a webform i instanciate an AccessClass object named myAccess
> and i call a method : myAccess.accessmethod()
>
> I want to insure that no two webforms run simultaneouslly the code in
> accessMethod()
>
> So the code of accessMethode() is
>
> void accessMethod()
> {
> lock(this)
> {
> ... code ...
> }
> }
>
> My questions are :
> Is this insure my goal ? Is my code a critical section for all clients ?
> I have a doubt because each webform has his proper instance of AccessClass.
> If two webforms instanciate an AccessClass object and call AccessMethod() at
> the same time, there is two different objects so if the critical section is
> relative to the object there is no critical section among all clients.
>
> If my solution is bad, an other idea is to pass a reference to the
> "Application" object to myMethod and to use it as the lock parameter. Indeed
> "Application" is shared between all clients.
> Is it a better idea ?
>
> If not, what is the solution ?
>
> Thanks,
>
> Christian
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Using template in safety-critical system (flight critical system) aeromarine C++ 15 02-18-2008 09:09 AM
IISState output, hung on critical section? James Hunter Ross ASP .Net 1 11-08-2005 06:06 PM
Can we view a single Asp.net page as one 'critical section' for identical http requests? itaitai2003@yahoo.com ASP .Net Security 0 01-25-2005 07:08 AM
Re: session ... critical section problem in vb+asp dot net Bob Barrows ASP .Net 0 02-27-2004 12:12 PM
mutex? protecting global data/critical section Dave Brueck Python 2 09-19-2003 08:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57