In the windows service, use patterns winform directly drag the timer control uses the timer is not possible, after starting the timer and the service will find not implemented. So how does using a timer in windows service?
Do not use direct drag control mode, defined directly in the code behind . details as follows:
// Windows service start event protected the override void the OnStart ( String [] args) { the System.Timers.Timer timer1 = new new the System.Timers.Timer ( 1000 ); timer1.Elapsed + = new new System.Timers.ElapsedEventHandler (Timer1_Tick); timer1 .Enabled = to true ; } Private void Timer1_Tick ( Object SENDER, EventArgs E) { // timer processing code }
In the present embodiment, the timer will be executed every 1s, the specific implementation process defined in Timer1_Tick process.