あにす #6359(2008/05/27 19:34 GMT) [ C# ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
using System; using System.Timers; class Program { static void Main(string[] args) { using(Timer timer = new Timer(1000)) { timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); timer.Start(); bool flag = true; while(flag) { ConsoleKeyInfo conKeyInfo = Console.ReadKey(true); ConsoleKey conKey = conKeyInfo.Key; switch(conKey) { case ConsoleKey.P: timer.Enabled = !timer.Enabled; break; case ConsoleKey.Q: flag = false; break; } } timer.Close(); } } static void timer_Elapsed(object sender, ElapsedEventArgs e) { Console.Out.WriteLine("a"); } }
Rating0/0=0.00-0+
[ reply ]
あにす
#6359()
[
C#
]
Rating0/0=0.00
System.Timers.Timerクラスを使用しています。Timerクラスは指定した間隔でイベントを発生させます。
後はループを回して、その中でTimerの停止、再開を切り替えています。
Rating0/0=0.00-0+
[ reply ]