Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public static object synLock = new object();
static int x = 10;
public static void Get1()
{
   try
   {
       Monitor.Enter(synLock);
       {
           
           x++;
       }
   }
   catch (Exception exx)
   {
       Console.WriteLine(exx.Message);
   }
   finally
   {
      
   }
}


in above code I have write Monitor.Enter(synLock)but not Moniter.Exit() in this Code and above code call by two different thread then is it working and who is responsible for releasing lock in above code.
Posted
Updated 5-May-14 0:11am
v3
Comments
[no name] 5-May-14 6:16am    
Here is answer
http://stackoverflow.com/questions/15023862/lock-keyword-calls-monitor-enterobject-or-enterobject-boolean
Sergey Alexandrovich Kryukov 5-May-14 7:55am    
Answer to what?
—SA
Sergey Alexandrovich Kryukov 5-May-14 7:54am    
Not a question. This code without monitor exit is disastrous, you should never do it. What's the purpose? Why using monitor at all?
—SA
Er. Dinesh Sharma 6-May-14 0:05am    
But the code is work fine without Monitor.Exit() I want to know that which thread is releasing this locked Monitor.
Bernhard Hiller 6-May-14 7:56am    
What do you mean with "working fine"? That the second call hangs?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900