SoFunction
Updated on 2025-03-07

C# Use timer instance code in windows service


//Start event
        protected override void OnStart(string[] args)
        {
//Timed events
            MyTimer();
        }

//End the event
        protected override void OnStop()
        {
writeLog("Service end time:" + ("yyyy-MM-dd HH:mm:ss"));
        }


//Instantiation
        private void MyTimer()
        {
            MT = new (30000);
            += new (MTimedEvent);
            = true;

        }

//Construction example Interval time event
        private void MTimedEvent(object source, e)
        {

//Implementation method

        }