私は C# のコーディングの初心者です。最初のプログラムでは、10 秒ごとにコンソール アプリケーションをリロードするタイマーが必要です。出来ますか?例を書いていただけますか?
1 に答える
2
アプリケーションを「リロード」する代わりに、通常、TIMEr を使用してアプリケーション内の特定のルーチンを定期的にトリガーします。
class Program
{
static void Main()
{
Console.WriteLine("Starting timer");
var timer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
timer.Elapsed += OnTimer;;
timer.Enabled = true;
Console.WriteLine("Press any key to shut down");
Console.ReadKey();
}
static void OnTimer(object source, ElapsedEventArgs e)
{
// This code will run every 10 seconds
Console.WriteLine("In timer");
}
}
于 2013-11-07T18:14:15.057 に答える