Lock keyword in C#

Sourav.Kayal
Posted by Sourav.Kayal under C# category on | Points: 40 | Views : 986
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Xml;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;
namespace BlogProject
{
class LockTest
{
static Int32 Value = 0;
public static void Increment()
{
Value += 1;
Console.WriteLine(Value);
}

}


class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 5000; i++)
{
Thread t1 = new Thread(new ThreadStart(LockTest.Increment));
lock (t1)
{
t1.Start();
}

Thread t2 = new Thread(new ThreadStart(LockTest.Increment));
lock (t2)
{
t2.Start();
}
}
Console.ReadLine();
}
}
}

Comments or Responses

Login to post response