At this point I am not very well apprehended with the sleep and thread combination, need to more research on these, need to review the original classes and constructors. Key work lock" did not resolve either. Link

using System;
using System.Threading;
//csc thread_Enter_Exit_sleep.cs
public class Test
{
//public static int n = 0;
static readonly object countLock = new object();
public static int n = 0;
//public string str = "";
static void Main()
{
Console.Write("Enter sleep time: ");
string str = Console.ReadLine();
if (str!="") { n = int.Parse(str); } else { n = 0 ;}
ThreadStart job = new ThreadStart(ThreadJob);
Thread thread = new Thread(job);
thread.Start();
Thread.Sleep(n);
for (int i=0; i < 3; i++)
{
Console.WriteLine ("Start--caller--Primary---" + i);
Monitor.Enter(countLock);
Console.WriteLine ("cycle count={0}", i);
Console.WriteLine ("Exit--caller-primary---{0}", i);
Monitor.Exit(countLock);

}
Console.WriteLine ("--caller----- Monitor--Join");
thread.Join();
//Console.WriteLine ("Final count: {0}", n);
Console.ReadLine();
}

static void ThreadJob()
{
for (int i=0; i < 5; i++)
{
Thread.Sleep(n);
Console.WriteLine ("\t\t\tStart Monitor/Lock--Secondary---{0}", i);
Monitor.Enter(countLock);
Console.WriteLine ("\t\t\t\t2ndcycle count={0}", i);
Console.WriteLine ("\t\t\tExit--Secondary---{0}", i);
Monitor.Exit(countLock);
// Thread.Sleep(40);
}
}
}
 

depending upon the system and C# compiler result may vary when time is "0". In Command SDK, the second process that was delegated in the caller, kicked in after two rounds, where as in another compiler, the caller completed it's own routine first then went for delegated ones. See second image

The another compiler "Sharp-Developer", processed

 
 
The modification

using System;
using System.Threading;
//csc thread_enter_exit_lock.cs
public class Test
{
//public static int n = 0;
static readonly object countLock = new object();
public static int n = 0;
//public string str = "";
static void Main()
{
Console.Write("Enter sleep time: ");
string str = Console.ReadLine();
if (str!="") { n = int.Parse(str); } else { n = 0 ;}
ThreadStart job = new ThreadStart(ThreadJob);
Thread thread = new Thread(job);
thread.Start();

for (int i=0; i < 3; i++)
{
Thread.Sleep(n);
Console.WriteLine ("Start--caller--Primary---" + i);
Monitor.Enter(countLock);
lock(countLock);
Console.WriteLine("Thread: {0} in caller : ", Thread.CurrentThread.GetHashCode());
Console.WriteLine ("cycle count={0}", i);
Console.WriteLine ("Exit--caller-primary---{0}", i);
Monitor.Exit(countLock);

}
Console.WriteLine ("--caller----- Monitor--Join");
thread.Join();
//Console.WriteLine ("Final count: {0}", n);
Console.ReadLine();
}

static void ThreadJob()
{
for (int i=0; i < 5; i++)
{
Thread.Sleep(n*5);
Console.WriteLine ("\t\t\tStart Monitor/Lock--Secondary---{0}", i);
Monitor.Enter(countLock);
Console.WriteLine("\t\t\tThread: {0} in second : ", Thread.CurrentThread.GetHashCode());
Console.WriteLine ("\t\t\t\t delgated count={0}", i);
Console.WriteLine ("\t\t\tExit--Secondary---{0}", i);
Monitor.Exit(countLock);
// Thread.Sleep(40);
}
}
}
 

with the modification