Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Console Anwendung mit Timer

17.10.2019 (👁2654)

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

    }

}