using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Timers; using System.Windows.Forms; namespace Threading_Demo3 { class Program { static void Main(string[] args) { demo demo1 = new demo(); demo1.spin (); Console.ReadLine(); } } class demo { private Action action1 { get; set; } private Action action2 { get; set; } private Action action3 { get; set; } private Action action4 { get; set; } private int count { get; set; } private int count1 { get; set; } public System.Timers.Timer timer1 { get; set; } public demo() { this.action1 = new Action(this.say); this.action2 = new Action(this.spin); this.action3 = new Action(this.spin2); this.action3 = new Action(this.spin3); this.count = 0; this.count1 = 0; this.timer1 = new System.Timers.Timer(); this.timer1.Interval = 15; this.timer1.Elapsed += this.say2; } private void spin2() { Thread.Sleep(12); this.action1.Invoke(); this.action4.Invoke(); } private void spin3() { Thread.Sleep(11); if (count<=180) { this.action1.Invoke(); this.action2.Invoke(); } } private void say2(object sender, ElapsedEventArgs e) { this.count1++; if (this.count1 <= 180) { Console.WriteLine("{0}\tLong Live TouHou!\t{1}", count1.ToString(), DateTime.UtcNow.ToString()); } else { this.timer1.Stop(); } } private void say() { this.count++; Console.WriteLine("{0}\tLong Live TouHou!\t{1}",count.ToString(),DateTime.UtcNow.ToString()); Form forms = new Form(); forms.Text = DateTime.UtcNow.ToString(); forms.ShowDialog(); Thread.Sleep(50); forms.Close (); } public void spin() { Thread.Sleep(12); this.action1.Invoke(); this.action3.Invoke(); } } }