NetworkKinectCore.NetworkKinectCore.ShutdownSensor C# (CSharp) Method

ShutdownSensor() public method

public ShutdownSensor ( ) : void
return void
        public void ShutdownSensor()
        {
            forceStop = true;

            //Stop the update timer
            if (updateTimer != null)
            {
                updateTimer.Stop();
                updateTimer.Elapsed -= updateTime_Elapsed;
                updateTimer.Dispose();
                updateTimer = null;
            }

            int count = 0;
            int maxCount = 50;
            while (count < maxCount) //Wait for the core to stop
            {
                if (!isRunning)
                {
                    break;
                }
                Thread.Sleep(10);
            }
            if (count >= maxCount && isRunning)
            {
                throw new Exception("Could not stop feedback core!");
            }

            //TODO: Somehow, the avaliable Kinects datagrid needs to be forced to update here so it knows the server is stopped
        }

Usage Example

        public void UpdateGUI(KinectBase.MasterSettings settings)
        {
            if (kinectID.HasValue)
            {
                masterSettings = settings;
                dynamic tempSettings = masterSettings.kinectOptionsList[kinectID.Value];
                kinectSettings = (NetworkKinectSettings)tempSettings;


                //Shutdown the server, if it is running
                bool wasRunning = false;
                if (kinectCore.isKinectRunning)
                {
                    kinectCore.ShutdownSensor();
                    wasRunning = true;
                }

                //Update the skeleton server and joint mappings
                serverNameTextBox.Text           = kinectSettings.serverName;
                jointMappingDataGrid.ItemsSource = kinectSettings.jointMappings;
                jointMappingDataGrid.Items.Refresh();

                //Update the physical position
                xPosTextBox.Text  = kinectSettings.kinectPosition.X.ToString();
                yPosTextBox.Text  = kinectSettings.kinectPosition.Y.ToString();
                zPosTextBox.Text  = kinectSettings.kinectPosition.Z.ToString();
                yawTextBox.Text   = kinectSettings.kinectYaw.ToString();
                pitchTextBox.Text = kinectSettings.kinectPitch.ToString();
                rollTextBox.Text  = kinectSettings.kinectRoll.ToString();

                //Update the hand grab data
                lhServerTextBox.Text  = kinectSettings.lhServerName;
                lhChannelTextBox.Text = kinectSettings.lhChannel.ToString();
                rhServerTextBox.Text  = kinectSettings.rhServerName;
                rhChannelTextBox.Text = kinectSettings.rhChannel.ToString();

                //Restart the server if it was running to begin with
                if (wasRunning)
                {
                    kinectCore.StartNetworkKinect();
                }
            }
        }