Создать таймер - C#
Формулировка задачи:
Создать таймер обратного отчёта?(Язык Си Шарп,консольное приложение)
Решение задачи: «Создать таймер»
textual
Листинг программы
using System;
using System.Timers;
namespace ReverseCount
{
class Program
{
public static int i = 100;//Отсчет с числа...
static void Main(string[] args)
{
Console.Title = "[C#]Reverse Count";
ReverseCount();
while (true)
if (Console.ReadKey().Key == ConsoleKey.Escape)
Environment.Exit(0);
}
public static void ReverseCount()
{
Timer tmr = new Timer();
tmr.Interval = 1000;
tmr.Enabled = true;
tmr.Elapsed += RTCount;
}
private static void RTCount(object sender, ElapsedEventArgs e)
{
if (i >= 0)
{
Console.WriteLine(i);
i--;
}
}
}
}