/// <summary>
        /// Adds the new skeletal drawing object to the queue to be processed
        /// </summary>
        /// <param name="skeletalData">new object with the data</param>
        /// <returns>number tasks outstanding in the queue</returns>
        public int AddToQueue(SkeletalData skeletalData)
        {
            //Decrement the semaphore to make sure the spot is available
            this.requestSkeletalData.WaitOne();

            lock (_threadLock)
            {
                dataQueue.Enqueue(skeletalData);
            }

            //Increament the semaphore to indicate there is work to do
            int previousCount = handleRequests.Release();

            return previousCount;
        }
        /// <summary>
        /// Processes the new skeleton data by passing the new object to the respective thread and checks the
        /// conditions if the gesture recognition has not stopped or started again or the first time
        /// </summary>
        /// <param name="skeletalData">the new skeleton information object</param>
        /// <returns>Processing result (success or failure)</returns>
        private int ProcessNewSkeletalData(SkeletalData skeletalData)
        {
            int processingResult = (int)ResultCodes.Success;

            do
            {
                if (skeletalData == null)
                {
                    processingResult = (int)ResultCodes.OutOfMemory;
                    break;
                }

                if (!this.stopVisualThreads)
                {
                    SkeletalDrawing.SkeletalDrawingData newDrawingData = new SkeletalDrawing.SkeletalDrawingData();
                    newDrawingData.SetSkeletalFrame(skeletalData.SkeletonFrame);
                    this.skeletalDrawingObject.AddToQueue(newDrawingData);
                }

                if (!this.trackedState && CheckIntialCondition(skeletalData) == (int)ResultCodes.GestureDetected)
                {
                    skeletalDataLogger.Debug("this.trackedstate is true");
                    this.trackedState = true;
                }

                this.stopGestureRecognition = StopGestureRecognition(skeletalData);

                if (this.trackedState)
                {

                    if (!this.stopGestureRecognition)
                    {
                        GestureDispatcher.GestureData newGestureData = new GestureDispatcher.GestureData();
                        newGestureData.SetSkeletalFrame(skeletalData.SkeletonFrame);
                        skeletalDataLogger.Debug("traked state is true drawing data added into processor queue");

                        this.gestureDispatch.StopVisualThread = this.stopVisualThreads;
                        this.gestureDispatch.ProcessNewGestureData(newGestureData);
                    }
                    else
                    {
                        this.trackedState = false;
                    }
                }

            } while (false);

            return processingResult;
        }
        /// <summary>
        /// Checks the condition if the Gesure recognition need to be stopped
        /// </summary>
        /// <param name="skeletalData">the new skeleton information object</param>
        /// <returns>true/false based on the conditions matched</returns>
        private bool StopGestureRecognition(SkeletalData skeletalData)
        {
            bool stopResult = false;
            SkeletonFrame currentFrame = skeletalData.SkeletonFrame;

            foreach (SkeletonData data in currentFrame.Skeletons)
            {
                if (SkeletonTrackingState.Tracked == data.TrackingState)
                {
                    Joint headJoint = data.Joints[JointID.Head];
                    Joint rightHandJoint = data.Joints[JointID.HandRight];

                    Joint leftHandJoint = data.Joints[JointID.HandLeft];

                    if (rightHandJoint.Position.Y > headJoint.Position.Y && leftHandJoint.Position.Y > headJoint.Position.Y)
                    {
                        stopResult = true;
                        break;
                    }
                }
            }

            return stopResult;
        }
        /// <summary>
        /// Checks the intial condition if the gesture recognition need to be started
        /// </summary>
        /// <param name="skeletalData">the new skeleton information object</param>
        /// <returns>condition detected - different code values</returns>
        private int CheckIntialCondition(SkeletalData skeletalData)
        {
            int conditionCheck = -1;
            SkeletonFrame currentFrame = skeletalData.SkeletonFrame;

            foreach (SkeletonData data in currentFrame.Skeletons)
            {
                if (SkeletonTrackingState.Tracked == data.TrackingState)
                {
                    Joint headJoint = data.Joints[JointID.Head];
                    Joint rightHandJoint = data.Joints[JointID.HandRight];
                    Joint leftHandJoint = data.Joints[JointID.HandLeft];

                    if (this.stopGestureRecognition)
                    {

                        conditionCheck = (int)ResultCodes.GestureDetectionFailed;
                        break;

                    }

                    if (rightHandJoint.Position.Y > headJoint.Position.Y && leftHandJoint.Position.Y > headJoint.Position.Y)
                    {
                        conditionCheck = (int)ResultCodes.GestureDetectionFailed;
                        break;
                    }

                    if (rightHandJoint.Position.Y > headJoint.Position.Y && leftHandJoint.Position.Y < headJoint.Position.Y)
                    {
                        conditionCheck = (int)ResultCodes.GestureDetected;
                        break;
                    }
                }
            }

            return conditionCheck;
        }