class Program
{
static Barrier barrier =
new Barrier(
2, b => Console.WriteLine(
"
End of phase {0}
", b.CurrentPhaseNumber +
1));
static
void PalyMusic(
string name,
string message,
int second)
{
for (
var i =
1; i <=
3; i++)
{
Console.WriteLine(
"
----------------------------------
");
Thread.Sleep(TimeSpan.FromSeconds(second));
Console.WriteLine(
"
{0} Start to {1}
", name, message);
Thread.Sleep(TimeSpan.FromSeconds(second));
Console.WriteLine(
"
{0} finisheds to {1}
", name, message);
barrier.SignalAndWait();
}
}
static
void Main()
{
var t1 =
new Thread(() => PalyMusic(
"
the guitarist
",
"
paly an amzaing solo
",
5));
var t2 =
new Thread(() => PalyMusic(
"
the singer
",
"
sing his song
",
2)); t1.Start(); t2.Start(); } }