473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread sincronization using lock.


I have tested that using locks for sinchronize calls to a web service
does not work correctly. Surely I am doing something wrong.

I have a "global" object for the "semaphore":

public object oLockOfWebService = new object();

And we have two concurrent libraries (one in c# and another in vb.net)
that realize calls to a webservice with this code:

Project A:

SyncLock Me.oGeneric.oLockOfWebService
data = WSClass.GetEventInfo(GuidAgent)
End SyncLock
And the c# code of the project B:

lock (this.oGenericData.oLockOfWebService)
{
oDataTerminalInfo =
this.IrmWS.GetTerminalInfo(this.AgentGuid);
}
I have tested (using strings logs) that sometimes one webmethod of the
webservice is called when the other HASN´T finished).

Any idea?

Thanxs in advance,
Jun 14 '07 #1
3 2435
Beto wrote:
>
I have tested that using locks for sinchronize calls to a web service
does not work correctly. Surely I am doing something wrong.

I have a "global" object for the "semaphore":

public object oLockOfWebService = new object();

And we have two concurrent libraries (one in c# and another in vb.net)
that realize calls to a webservice with this code:

Project A:

SyncLock Me.oGeneric.oLockOfWebService
data = WSClass.GetEventInfo(GuidAgent)
End SyncLock
And the c# code of the project B:

lock (this.oGenericData.oLockOfWebService)
{
oDataTerminalInfo =
this.IrmWS.GetTerminalInfo(this.AgentGuid);
}
I have tested (using strings logs) that sometimes one webmethod of the
webservice is called when the other HASN´T finished).

Any idea?
It appears your oLockOfWebService is an instance member of the class.
If each library (c# and VB.NET) have their own unique instance of the
class which has its own instance of oLockOfWebService, then each lock
will be different as well.

You state your object is "global", but is it single or are there
multiple instances? There is nothing in the above code snippets to
suggest a single instance.
--
Tom Porterfield
Jun 14 '07 #2
Hi,

"Beto" <al**********@NOSPAM-PLEASE-yahoo.eswrote in message
news:uC*************@TK2MSFTNGP06.phx.gbl...
>
I have tested that using locks for sinchronize calls to a web service does
not work correctly. Surely I am doing something wrong.
You mean in the client or in the web service itself?

I have a "global" object for the "semaphore":

public object oLockOfWebService = new object();
that instance is a member of what class?
How all the threads in your program get access to it? (I find it weird you
do not declare it as static).
And we have two concurrent libraries (one in c# and another in vb.net)
that realize calls to a webservice with this code:
If you have two processes each one will have their own copy of the
semaphore.

Not only that, but why you need two libraries? you can have only one and use
it from either VB.net or C#
Project A:

SyncLock Me.oGeneric.oLockOfWebService
data = WSClass.GetEventInfo(GuidAgent)
End SyncLock
And the c# code of the project B:

lock (this.oGenericData.oLockOfWebService)
{
oDataTerminalInfo = this.IrmWS.GetTerminalInfo(this.AgentGuid);
}
I have tested (using strings logs) that sometimes one webmethod of the
webservice is called when the other HASN´T finished).

Any idea?
Of course, they are two different projects both will have a copy of the
library and each will have a copy of your semaphore.


Jun 14 '07 #3

Hi Ignacio,

it wasn´t a thread sincronization error. The locks worked well. (My
write-logs of this bug were wrong).

It´s a problema of a "database consistency" in a table from sql server.

Sometimes a call to the database flushed to our app an exception, this
"random" exception is the reason why I supposed it was a threading bug.

Anyway, Thanxs everybody!!! ;)

Ignacio Machin ( .NET/ C# MVP ) escribió:
Hi,

"Beto" <al**********@NOSPAM-PLEASE-yahoo.eswrote in message
news:uC*************@TK2MSFTNGP06.phx.gbl...
>I have tested that using locks for sinchronize calls to a web service does
not work correctly. Surely I am doing something wrong.

You mean in the client or in the web service itself?

>I have a "global" object for the "semaphore":

public object oLockOfWebService = new object();

that instance is a member of what class?
How all the threads in your program get access to it? (I find it weird you
do not declare it as static).
>And we have two concurrent libraries (one in c# and another in vb.net)
that realize calls to a webservice with this code:

If you have two processes each one will have their own copy of the
semaphore.

Not only that, but why you need two libraries? you can have only one and use
it from either VB.net or C#
>Project A:

SyncLock Me.oGeneric.oLockOfWebService
data = WSClass.GetEventInfo(GuidAgent)
End SyncLock
And the c# code of the project B:

lock (this.oGenericData.oLockOfWebService)
{
oDataTerminalInfo = this.IrmWS.GetTerminalInfo(this.AgentGuid);
}
I have tested (using strings logs) that sometimes one webmethod of the
webservice is called when the other HASN´T finished).

Any idea?

Of course, they are two different projects both will have a copy of the
library and each will have a copy of your semaphore.

Jun 15 '07 #4

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

Similar topics

0
1311
by: fowlertrainer | last post by:
Hello ! I have been created a Zope (Python) Product. But it is must store inner global definitions (some conversion parameters), what I need to change in only one thread, or only once. See...
44
2318
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker...
31
2434
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
0
1223
by: Ivan | last post by:
Hi there My work on threads continues with more or less success. Here is what I'm trying to do: Class JobAgent is incharged for some tasks and when it's called it starts thread which performs...
7
439
by: Ivan | last post by:
Hi there My work on threads continues with more or less success. Here is what I'm trying to do: Class JobAgent is incharged for some tasks and when it's called it starts thread which performs...
2
2965
by: Gabriele Farina | last post by:
Hi, I'm tring to implement a Singleton object that should be specific for every thread who create it, not global. I tried a solution that seems to work, but I have a very poor knowledge of...
5
3778
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
3
3061
by: andreas.zetterstrom | last post by:
I'm implementing some different c++ classes which I want to be thread safe. All these classes contain lists or arrays of some kind. I'm using protected sections to make them thread safe. The...
12
2065
by: Ronny | last post by:
Thanks Chris, Looks nice but I miss the dual way communication. In the main thread to deliver paramters and data to the worker thread- how can I do that? Regards Ronny Take a look at the...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.