using System.data;
using System.threading;
using System.text;
class program{
static void main()
{int i=0;
while(true)
{i++;
thread.sleep(32);
console.writeline(DateTime.now.millonsecond);
if(i>=100)
{Console.readkey();}
}
}
}
输出的数之间差不是32而是47,31以前的还准确。99的时候是110.请问问题出在哪里,谁能给出一个精确的定时器,毫秒级的。我试了System.windows.timer,System.timer.timer;System.threading.timer;都不可以。不够精确,总有误差,难道是我的程序执行的时间太长,超过了定时的间隔吗?
using System.threading;
using System.text;
class program{
static void main()
{int i=0;
while(true)
{i++;
thread.sleep(32);
console.writeline(DateTime.now.millonsecond);
if(i>=100)
{Console.readkey();}
}
}
}
输出的数之间差不是32而是47,31以前的还准确。99的时候是110.请问问题出在哪里,谁能给出一个精确的定时器,毫秒级的。我试了System.windows.timer,System.timer.timer;System.threading.timer;都不可以。不够精确,总有误差,难道是我的程序执行的时间太长,超过了定时的间隔吗?
停止32毫秒有什么意义吗?试试把 32改成1000准确不准确
onsole.writeline(DateTime.now.millonsecond);
也是需要时间的。
这在物理上有个术语叫做“测不准原理”
int tmp=Environmnet.TickCont;
while(true)
{
tmp=Environmnet.TickCont-tmp;
if(tmp>37)
{
Envent();
break;
}
}