C# 比秒表更精确的计时器?

C# 比秒表更精确的计时器?,c#,kinect,clock,stopwatch,C#,Kinect,Clock,Stopwatch,在记录Kinect的位置时,我尝试使用秒表启动和停止: //process x and y coordinates public void calculateJoints(Skeleton skeleton) { Joint rightHand = skeleton.Joints[JointType.HandRight]; Joint leftHand = skeleton.Joints[JointType.HandRigh

在记录Kinect的位置时,我尝试使用秒表启动和停止:

   //process x and y coordinates
   public void calculateJoints(Skeleton skeleton)
    {          
        Joint rightHand = skeleton.Joints[JointType.HandRight];
        Joint leftHand = skeleton.Joints[JointType.HandRight];
        rightX = rightHand.Position.X;
        rightY = rightHand.Position.Y;         

    }

//start the stopwatch (tried to use a greater time between positions 1 and 5 vs 1 and 2
  public void processJointsAndRepeat(Skeleton skeleton)
  {
        startTime();
        while (numPositions < 5)
        {   
             calculateJoints(skeleton);
             numPositions++;
        }
        stopTime();
        double tempTime = calculateTimeElapsed();
  }

   //calculate time in milliseconds
   private double calculateTimeElapsed()
    {
        long milliseconds = stopWatch.ElapsedMilliseconds;
        return (double)milliseconds;
    }
//处理x和y坐标
公共空心计算点(骨架)
{          
Joint rightHand=skeleton.Joints[JointType.HandRight];
Joint leftHand=skeleton.Joints[JointType.HandRight];
rightX=右手位置.X;
rightY Y=右手位置Y;
}
//启动秒表(尝试在位置1和5与位置1和2之间使用更长的时间
公共void进程jointsandrepeat(骨架)
{
开始时间();
而(数量<5)
{   
计算点(骨架);
numPositions++;
}
停止时间();
double-TENTIME=CalculateTimeExpressd();
}
//以毫秒为单位计算时间
私人双重计算失效()
{
长毫秒=秒表。延时毫秒;
返回(双)毫秒;
}
但每当我尝试输入以时间为键的x、y和时间值时,它都会为重复键抛出一个错误。当我检索到TENTIME的值时,它只显示0

这是我的代码有问题吗,还是我需要更精确的秒表


我意识到要获得30 fps的时间是很困难的,所以如果你有任何其他的建议,那就太好了!我基本上只是想计算点之间的平均速度来调整音频文件的播放速度。谢谢!

秒表是普通Windows box上分辨率最高的环绕计时器。通过使用和,您可以使用较少花哨的函数来获得比MS更高的分辨率


请注意,您的问题可能与计时器无关,而与您未显示的其他代码有关…

秒表的分辨率是多少?您正在测量以纳秒为单位执行的代码。是的,ElapsedMilliseconds总是返回0。如果不故意放慢速度,您所做的事情毫无意义将代码转换为人工时间。使用计时器或线程。Sleep()。