473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Critical section in WebForms

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
Nov 18 '05 #1
2 1681
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
<Ch*******@discussions.microsoft.com> 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


Nov 18 '05 #2
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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian Alexander | last post by:
Hello; I am trying to protect some global data, which may, in the future, be accessed by threads. I'm not sure how to implement a locking mechanism in python. Here is the idea I'm trying to...
77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
2
by: Xarky | last post by:
Hi, I am trying to learn Critical Sections. I have written a small program. Source code problem below. What the program is doing is disabling the CRTL-C signal in the critical section. My...
2
by: Ed S | last post by:
HiAll, What would you suggest I use if I want to protect the creation of a singleton - in the instance() static method. In C++, I'd use a critical section. Thanks, --Ed
7
by: Piotrek Stachowicz | last post by:
Hi, I need to create the situation in my system, where no more critical sections can be initialized (win2000Server). I thought about creating a simple c# application and using the Monitor class....
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
3
by: Harry Whitehouse | last post by:
Hi! I've been migrating some legacy ISAPI appliations to .NET Webservice. In one, I call a third party routine which is not thread safe. In the ISAPI world, I put a critical section around the...
13
by: Hendrik van Rooyen | last post by:
Hi, I would like to do the following as one atomic operation: 1) Append an item to a list 2) Set a Boolean indicator It would be almost like getting and holding the GIL, to prevent a...
5
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.