Thread sincronization using lock.

  • Thread starter Thread starter Beto
  • Start date Start date
B

Beto

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,
 
Beto said:
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.
 
Hi,

Beto said:
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.
 
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ó:
 
Back
Top