2015-04-01 95 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