/*------------------------------------------------------------------------------------------- * 用来测试程序速度的类 * 创建:杨斌 2011-11-19 * ----------------------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using System.Windows.Forms; namespace GeneralLib { /// /// 用来测试程序速度的类 /// class TimerCount { /// /// 上次记录的毫秒数 /// private int TickCountBegin = 0; [DllImport("winmm")] static extern int timeGetTime(); /// /// 获取系统启动后经过的毫秒数 /// /// public static int TickCount() { return Environment.TickCount; //return timeGetTime(); } /// /// 开始计时,毫秒 /// public void StartCount() { TickCountBegin = TickCount(); } /// /// 获取开始计时后经过的时间,毫秒 /// /// public int GetCountMS() { return TickCount() - TickCountBegin; } public static void Delay(long ms) { Stopwatch t = Stopwatch.StartNew(); while (t.ElapsedMilliseconds < ms) { Application.DoEvents(); } } } }