paulo gomes

paulo gomes

  • NA
  • 9
  • 0

How to verify if a static class is running/active

Aug 24 2018 1:07 PM
Hi all,
 
The scenario is a multi-thread environment as below:
 
. a static class accessDLLlock has several internal methods.
. A static object _objectLocker is declared in the constructor.
. Each method in accessDLLLock executes a lock to _objectLocker  and then redirects the call to a method in a DLL that is non thread-safe (the reason for the lock)
.The next call to accessDLLLock   will add the request to the queue (FIFO) if the class is still locked; it will be answered only when the lock is released
 
QUESTION: how to know if accessDLLLock is running (or locked) before calling it?
 
Thank you for your time,
Paulo

Below part of the accessDLLLock code:
------------------------------------------
 
namespace Myservice
{
public static class accessDllLock
{
//declares the static object to synchronize the lock with incoming calls
static readonly object _objectLocker = new object();
 
public static string function_1_to_lock (string arg_input)
{
lock (_objectLocker)
try
{ statements to call the method function_1 in a DLL non thread safe }
}
public static string function_2_to_lock (string arg_input)
{
lock (_objectLocker)
try
{ statements to call the method function_2 in a DLL non thread safe }
}
...
}
 

Answers (2)