My code creates a number of Semaphores when it initializes. Each one is associated with a ftp server that my system will communicate with from multiple workflows.
As different instances of the same workflows start I inject the semaphores into the workflows depending on which ftp site that workflow is going to communicate with.
I’m getting a situation where it looks like 2 or more workflows which should contain the same Semaphore are trying to access the ftp servers more times than the capacity of the Semaphore should allow.
I’ve named the Semaphores because I thought I could retrieve the name at the point where the ftp connection is made so that I can check that the correct Semaphore is in the right workflow.
How do I access the name of a Semaphores?
I tried to build an object that inherits from Semaphores and add a name field but this does not work as Semaphore is Sealed
public class MySemaphore : System.Threading.Semaphore
{
string SemaphoreName = "Bob";
}
If you are using .NET 4.0 then use
SemaphoreSliminstead. It is not sealed.If you must use
Semaphorethen you will have to create your own class without subclassing it. You will have to punt on the polymorphism so it will not work insideWaitHandle.WaitAnyfor example, but it is a viable workaround.