Some task that can be periodically called by timer in thread
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace TimerExample { class Program { static void Main(string[] args) { Console.WriteLine("Working with Timer type\n"); TimerCallback timeCB = new TimerCallback(PrintTime); Timer t = new Timer(timeCB,"Hello from Main",0,1000); // Timer thread... Console.WriteLine("Hit to terminate..."); Console.ReadLine(); } static void PrintTime(object state) { Console.WriteLine("Time is:{0}",DateTime.Now.ToLongTimeString()); } } } |