55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.Timers;
|
|
|
|
namespace ThreadingTimersDemo
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
say say = new say();
|
|
say.Spin();
|
|
int count = 0;
|
|
while (true)
|
|
{
|
|
Thread.Sleep(16);
|
|
count++;
|
|
Console.WriteLine("{0}\t{1}",count,DateTime.UtcNow.ToString());
|
|
}
|
|
}
|
|
}
|
|
class say
|
|
{
|
|
public Action Repeat { get; set; }
|
|
public Action Operation { get; set; }
|
|
public int Count { get; set; }
|
|
public say()
|
|
{
|
|
Repeat = new Action(this.Spin);
|
|
Operation = new Action(this.SaySentence );
|
|
}
|
|
public void Spin()
|
|
{
|
|
Thread.Sleep(16);
|
|
if (this.Count<=600)
|
|
{
|
|
this.Operation.Invoke();
|
|
this.Count++;
|
|
this.Repeat.Invoke();
|
|
}
|
|
}
|
|
public void SaySentence()
|
|
{
|
|
//Console.WriteLine("Long Live TouHou!");
|
|
//Console.WriteLine(DateTime.UtcNow.ToString());
|
|
//Console.WriteLine(this.Count );
|
|
Console.WriteLine("{0}\t{1}",this.Count.ToString(),DateTime.UtcNow.ToString());
|
|
}
|
|
}
|
|
}
|