2015-04-01 93 views
-2

我正在读取事件处理程序中的传感器(kinect)数据,该事件在数据可用时(每秒30次)引发。我正在计算来自数据的关节角度。在.NET中每秒钟将数据流保存到文件中

在点击一个按钮时,我需要写关节角度数据到文件每秒(变量)5分钟(变量)。

有人可以请指出我正确的方向如何做到这一点。

我使用WPF,C#,Kinect的寡妇2 SDK

+0

不错的一个codeflare!你试过什么了? http://stackoverflow.com/help/how-to-ask – Mathemats 2015-04-01 03:06:40

+0

我可以简单地做System.IO.File.WriteAllText(@“c:\ data.txt”,jointAngles)。但我会保存太多的数据。我只想知道当数据以30次/秒的速度到达时,我只能以一/秒或两次/秒的速度写入数据,而这一点也只有5分钟。 – codeflare 2015-04-01 03:12:06

+0

平均30个角度然后写? – Axis 2015-04-01 03:18:52

回答

1

可以使用Timer

static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); 

void TimerInit(int interval) { 
    myTimer.Tick += new EventHandler(myTimer_Tick); //this is run every interval 
    myTimer.Interval = internal; 
    myTimer.Enabled = true; 
    myTimer.Start(); 
} 

private static void myTimer_Tick(object sender, EventArgs e) { 
    System.IO.File.WriteAllText(@"c:\path.txt", jointAngles); //You might want to append 
    if (reached 5 minutes or X write cycles) { 
     myTimer.Stop(); 
    } 
} 
+0

或'System.Threading.Timer'如果你不想引用Windows窗体。 – vesan 2015-04-01 03:42:06