Question

I am trying to call a function whose parameters are object sender and RoutedEventsArg e. I need those parameters since I have created a button on the main window related to this function and when I click the button it links to my function.

 protected void StartRecord(object sender,RoutedEventsArg e)
{
  // some stuff that creates a button and then does stuff
}

In another function, I need to call the above function stated above, but this second function has a parameter of AllFramesReadyArg e, not RoutedEventsArg e. So how do i call out the first function

    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
            this.StartRecord(sender, e);
        // does not work since parameter calls for RoutedEventArgs
    }
Was it helpful?

Solution

Your StartRecord is not part of the Kinect Toolbox. You appear to have written it and given it those two arguments. It doesn't need them, nor do you necessarily need the function.

You also do not want to be calling StartRecord in AllFramesReady. The AllFramesReady callback is fired every time all the frames are ready for processing (hence the function name), which happens roughly 30 times a second. You only need to tell it to record once.

Per your other question, StartRecord is a callback to a button -- it shouldn't be called in code. It is called when the user hits the associated button.

Just looking at the Kinect Toolbox code and the callbacks, your code should look something like this:

KinectRecorder _recorder;
File _outStream;
bool _isRecording = false;

private void KinectSetup()
{
    // set up the Kinect here

    _recorder = new KinectRecorder(KinectRecordOptions.Skeleton, _outStream);

    // some other stuff to setup
}

private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    SkeletonFrame skeleton;

    if (_isRecording && skeleton != null)
    {
        _recorder.Record(skeleton);
    }
}

public void StartRecord(object sender, RoutedEventsArg e)
{
    _isRecording = !_isRecording;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top