本帖最后由 崔增阳 于 2013-7-8 23:49 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace Demo
{
class Program
{
static int _count=0;
private static string s = "This string will appear one letter at a time. ";
static void Main(string[] args)
{
Timer MyTimer=new Timer(100);
MyTimer.Elapsed +=new ElapsedEventHandler(WriteChar);
MyTimer.Start();
Console.ReadKey();
Console.ReadKey(); 为什么要写两个ReadKey才能出正确结果呢?
}
public static void WriteChar(object source, ElapsedEventArgs e)
{
Console.Write(s[_count++%s.Length]);
}
}
}
为什么要写两个ReadKey才能出正确结果呢?
|