添加一个类public class HighResolutionTimer
{
private long start;
private long stop;
private long frequency; public HighResolutionTimer()
{
QueryPerformanceFrequency (ref frequency);
} public void Start ()
{
QueryPerformanceCounter (ref start);
} public void Stop ()
{
QueryPerformanceCounter (ref stop);
} public float ElapsedTime
{
get
{
float elapsed = (((float)(stop - start)) / ((float) frequency));
return elapsed;
}
} [System.Runtime.InteropServices.DllImport("KERNEL32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool QueryPerformanceCounter( ref long performanceCount);
[System.Runtime.InteropServices.DllImport("KERNEL32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool QueryPerformanceFrequency( ref long frequency);
}
调用:
HighResolutionTimer timer=new HighResolutionTimer();
///开始计时
timer.Start();//停止计时
timer.Stop();//获取时间
timer.ElapsedTime
{
private long start;
private long stop;
private long frequency; public HighResolutionTimer()
{
QueryPerformanceFrequency (ref frequency);
} public void Start ()
{
QueryPerformanceCounter (ref start);
} public void Stop ()
{
QueryPerformanceCounter (ref stop);
} public float ElapsedTime
{
get
{
float elapsed = (((float)(stop - start)) / ((float) frequency));
return elapsed;
}
} [System.Runtime.InteropServices.DllImport("KERNEL32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool QueryPerformanceCounter( ref long performanceCount);
[System.Runtime.InteropServices.DllImport("KERNEL32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool QueryPerformanceFrequency( ref long frequency);
}
调用:
HighResolutionTimer timer=new HighResolutionTimer();
///开始计时
timer.Start();//停止计时
timer.Stop();//获取时间
timer.ElapsedTime
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货