Lock Demo : Lock : Thread C# Examples


C# Examples » Thread » Lock »

 

Lock Demo





The lock keyword is used when working with multiple threads.
Its general form is shown here:




    
lock(obj)  {
        //  critical  section  
        }
    
   
  
   





    
using  System;
using  System.Threading;

class  MainClass  
{
    [STAThread]
    static  void  Main(string[]  args)
    {
            int  r  =  0;
            object  t  =  new  object();
        lock  (  t  )
        {  
            r++;
        }
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Lock