一、 定时任务
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Timers;
- namespace ConsoleApplication3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Timer t = new Timer();
- t.Elapsed += new ElapsedEventHandler(OnTimedEvent);
- t.Interval = 1000;
- t.Enabled = true;
- Console.Read();
- }
- private static void OnTimedEvent(object source, ElapsedEventArgs e)
- {
- Console.Clear();
- Console.WriteLine(DateTime.Now);
- }
- }
- }
二、 程序等待几秒,延迟执行
namespace ConsoleApplication2.selectSDF.tool
{
class SleepMillsecond
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern uint GetTickCount();
/// <summary>
/// 程序等待延迟执行
/// </summary>
/// <param name="ms">毫秒</param>
internal static void MySleep(uint ms)
{
uint start = GetTickCount();
Console.WriteLine("等待中............!");
while (GetTickCount() - start < ms)
{
//Console.WriteLine("等待中............!");
}
}
}
}