jeddai
jeddai

Reputation: 799

Kinect New Window Wpf

So I'm making a Kinect application using buttons, and to navigate the app, I'm making new windows for each button. I'm come across an issue I haven't been able to find any help at all on, and would appreciate any help.

So to open the new window, I'm using this:

private void button1_Click(object sender, RoutedEventArgs e)
{
    //SUPPOSED to uninitialize the Kinect
    UninitializeKinectSensor(this.Kinect;
    //To open the new window
    Window1 newwindow = new Window1();
    newwindow.Show();
    //To close the first window...
    Close();
{

SO that one line is supposed to uninitialize the Kinect so it'll be free for the new window to use, but when it goes to the new window, the Kinect freezes. If I use the mouse to go back to the first window, it works on the first window again, which it shouldn't.

I also added in this line in the initialization phase

public Window1()
{
    //Other init code is here, but this is the line I added. It doesn't seem to do anything.
    InitializeKinectSensor(this.Kinect);
}

Any help is greatly appreciated!! I'm sure it's something simple and I just failed miserably haha XD

Upvotes: 0

Views: 635

Answers (3)

oshadac
oshadac

Reputation: 1

Instead of using the "Show()" use "ShowDialog()".It's better if you can create a static class or method to initialize and uninitialized kinect.

public static void start()
        {
            KinectSensor.KinectSensors.StatusChanged += kinectSensorsStatusChanged;
            DiscoverSensor();
        }


 private static void kinectSensorsStatusChanged(object sender, StatusChangedEventArgs e)
        {

            KinectSensor oldSensor = Kinect;
            if (oldSensor != null)
            {
                UninitializeKinect();
            }
            var status = e.Status;
            if (Kinect == null)
            {
                //updateStatus(status);
                if (e.Status == KinectStatus.Connected)
                {

                    Kinect = e.Sensor;
                    DiscoverSensor();
                }
            }
            else
            {
                if (Kinect == e.Sensor)
                {
                    //updateStatus(status);
                    if (e.Status == KinectStatus.Disconnected ||
                        e.Status == KinectStatus.NotPowered)
                    {
                        Kinect = null;
                        sensorConflict = false;
                        DiscoverSensor();
                    }
                }
            }

        }

private static DispatcherTimer readyTimer;

private static void UninitializeKinect()
        {
            if (speechRecognizer != null && Kinect != null)
            {
                Kinect.AudioSource.Stop();
                Kinect.SkeletonFrameReady -= kinect_SkeletonFrameReady;
                Kinect.SkeletonStream.Disable();
                Kinect.Stop();
                //this.FrameSkeletons = null;
                speechRecognizer.RecognizeAsyncCancel();
                speechRecognizer.RecognizeAsyncStop();
            }

            if (readyTimer != null)
            {
                readyTimer.Stop();
                readyTimer = null;
            }
        }

Upvotes: 0

James Ashley
James Ashley

Reputation: 549

Depends alot on what UninitializeKinectSensor is actually doing. Just as a quick fix, though, you can try calling uninitialize on a background worker and see if that helps at all.

Upvotes: 0

Florent Gz
Florent Gz

Reputation: 934

Do you really have to create a new window instead of using pages?

In your MainWindow you create a frame that takes all the window and use this frame to navigate between pages. This way, you'll keep the focus of the kinect in your whole application.

Upvotes: 1

Related Questions