Add tags

Add tags to the following comment
こんなんで題意に添えているでしょうか?
System.Timers.Timerクラスを使用しています。Timerクラスは指定した間隔でイベントを発生させます。
後はループを回して、その中でTimerの停止、再開を切り替えています。
 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");
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...