title: How to use lock to manage access to different type of resources?
body: <p>I need to synchronize execution of piece of code for several different types of resources.</p>
  <p>For a given resource type, only one thread should be able to execute piece of code at a time. Same piece of code can be executed by multiple threads as long as all threads are working on different types of resources.</p>
  <p>Let me know if following approach is right or wrong.</p>
  <p>Function GetResourceTypeLockObject returns different lock objects based on given type in parameter. Each object is previously created readonly object.</p>
  <pre><code>GetResourceTypeLockObject(TypeEnum type)
  {
    
   if type == 1 
     return type1LockObject;
  
   else if type == 2
     return type2LockObject;
  
   else if type == 3
     return type3LockObject;
  }
  
  
  WorkOnResource(TypeEnum type)
  {
   var lockObject = GetResourceTypeLockObject(type);
  
  lock(lockObject)
  {
   // Manipulate resource of given type
  
  }
  
  }
  </code></pre>