Console mit Timer einbinden
Code Beispiel zum erstellen einer Consollen Anwendung mit einem Timer
in Visual STudio 2019
Console in .Core
using System;
using System.Timers;
namespace ConsoleApp_Core2
{
class Program
{
//< variables >
static int iTimer = 0;
static Timer timer = new Timer(1000);
//</ variables >
static void Main(string[] args)
{
//------< Main >------
//create a timer
timer.Elapsed += Timer_Elapsed;
//< init >
timer.Start();
Console.WriteLine("Start reading");
//</ init >
//wait until enter any key
Console.ReadLine();
//stop timer when closing console
timer.Stop();
//------<// Main >------
}
#region events
private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
//---------< Timer_Elapsed() >------
iTimer++;
Console.WriteLine(iTimer + " " + DateTime.Now ); //write loop and time to console output
// clear
GC.Collect(); //*???
//---------</ Timer_Elapsed() >------
}
#endregion / events
}
}
|