You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
639 B
C#

/*
* C# Program to Demonstrate Lock in Thread
*/
using System;
using System.Threading;
class Program
{
static readonly object _object = new object();
static void TEST()
{
lock (_object)
{
Thread.Sleep(100);
Console.WriteLine(Environment.TickCount);
}
}
static void Main()
{
for (int i = 0; i < 10; i++)
{
ThreadStart start = new ThreadStart(TEST);
new Thread(start).Start();
}
}
}
/*
900500
900593
900687
900796
900890
900999
901092
901186
901295
901389