You don't need to launch a thread for this purpose. Use the System.Timers.Timer class instead.
Example:
using System;
using System.Timers;
namespace ConsoleApplication4
{
class Program
{
private static Timer m_timer;
static void Main (string[] args)
{
m_timer = new Timer (5 * 1000.0 ); // set timer interval to 5 min.
m_timer.Elapsed += m_timer_Elapsed;
m_timer.Start ();
/* Do other real work here in the meantime
* --------------------------------------- */
Console.WriteLine ("Press carriage return to end program.");
Console.ReadLine ();
}
static void m_timer_Elapsed (object sender, ElapsedEventArgs e)
{
Console.WriteLine (DateTime.Now.ToString ());
}
}
}
No comments:
Post a Comment