Search code examples
c#.netwpfkinect-sdk

Save data stream to a file every second in .NET


I am reading sensor(kinect) data in the event handler of an event that gets raised when the data is available (at 30 times/sec). I am calculating joint angles from the data.

Up on clicking a button,I need to write joint angle data to file every second(variable) for 5 minutes(variable).

Can some one please point me in right direction on how to accomplish this.

I am using WPF, C#, kinect for widows 2 SDK


Solution

  • You can use a 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();
        }
    }