class Application { public void Run() { int intQueryInterval = Properties.Settings.Default.QueryInterval; DateTime dteLastCheck = DateTime.Now; while (true) { TimeSpan t = DateTime.Now - dteLastCheck; if (t.Seconds > intQueryInterval) { DoSth(); dteLastCheck = DateTime.Now; } System.Threading.Thread.Sleep(1); } } private void DoSth() { //... } }
private System.Threading.Thread aaa; private void Run() { aaa = new System.Threading.Thread(Process_start); aaa.Start(); } private void Process_start() { while (true) { DoSth(); System.Threading.Thread.Sleep(10000); } }
namespace Test { class Program { private static void Main(string[] args) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 1000; timer.Elapsed += new EventHandler(timer_Elapsed); timer.Enabled = true; } private void timer_Elapsed(object sender , EventArgs e) { //do something } } }