GetTickCount函数

函数功能:GetTickCount返回(retrieve)从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD。
求一个在c#中测试函数所用时间的函数或是方法。类似上边的api函数!!!!

解决方案 »

  1.   

    使用Stopwatch 就可以了:
    System.Diagnostics.Stopwatch t = System.Diagnostics.Stopwatch.StartNew();
    Console.WriteLine(t.Elapsed);
      

  2.   

            [DllImport("kernel32.dll")]
            public static extern int GetTickCount();        private void button1_Click(object sender, EventArgs e)
            {
                int iTime = GetTickCount();            for(int i=0;i<1000;i++)
                {
                    System.Threading.Thread.Sleep(2);
                }            MessageBox.Show( (GetTickCount() - iTime).ToString() );
            }