using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers; // 定时器
namespace Demo4Timers
{
class Program
{
static int counter = 0;
static string displayString = "Hello C#!";
static void WriteChar(object source,ElapsedEventArgs e)
{
Console.Write(displayString[counter++ % displayString.Length]); // 一个单词一个单词写!
}
static void Main(string[] args)
{
Timer myTimer = new Timer(100);
myTimer.Elapsed += new ElapsedEventHandler(WriteChar);
myTimer.Start();
System.Threading.Thread.Sleep(200); // 每2毫秒执行一次
Console.ReadKey();
}
}
}
执行效果很有科技感!
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6797729.html,如需转载请自行联系原作者