Hello,
You have a few options.
This is the code for the simple component based timer :
using System; using System.Collections.Generic; using System.Text; using System.Timers;
namespace ConsoleApplication1 { class Program { static Timer timer; static void Main(string[] args) { timer = new Timer(5 * 60); // 5 Mins timer.Enabled = true; timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); System.Console.WriteLine("Press any key to exit"); System.Console.ReadKey(); }
static void timer_Elapsed(object sender, ElapsedEventArgs e) { System.Console.WriteLine("Beep"); } } }
And now with the Thread Timer class (note the Using Change ) :
using System; using System.Collections.Generic; using System.Text; using System.Threading;
namespace ConsoleApplication1 { class Program { static Timer timer; static void Main(string[] args) { timer = new Timer( Beeper, null, new TimeSpan(0), new TimeSpan(0, 5, 0)); System.Console.WriteLine("Press any key to exit"); System.Console.ReadKey(); } static void Beeper(object state) { System.Console.WriteLine("Beep");
} } }
You can add code to the service pause to pause and resume the timers. Hope this help.
|