rt, C# codes as below:
usingSystem;
usingSystem.Threading;
namespaceMConsoleApp
{
classProgram
{
staticvoidMain(string[]args)
{
PrintHelper.MaxCycle=30;
Threadthread1=newThread(newThreadStart(PrintHelper.Print)){Name="A"};
Threadthread2=newThread(newThreadStart(PrintHelper.Print)){Name="B"};
Threadthread3=newThread(newThreadStart(PrintHelper.Print)){Name="C"};
thread1.Start();
thread2.Start();
thread3.Start();
Console.ReadKey();
}
}
classPrintHelper
{
///<summary>
///Helpcurrentthreadkeepintouchwithotherthreads.
///</summary>
privatestaticintcounter;
///<summary>
///Definetheexitofmethodcycle.
///</summary>
publicstaticintMaxCycle{get;set;}
publicstaticvoidPrint()
{
while(counter<MaxCycle)
{
stringname=Thread.CurrentThread.Name;
if((counter%3==0&&name=="A")||(counter%3==1&&name=="B")||(counter%3==2&&name=="C"))
{
lock("lockthisCode!")
{
if(counter<MaxCycle)
{
Console.Write(name);
counter++;
}
}
}
}
}
}
}