public int AddToQueue(SkeletalDrawingData skeletalDrawingData)
        {
            //Decrement the semaphore to make sure the spot is available
            this.requestSkeletalData.WaitOne();

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

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

            return previousCount;
        }
        /// <summary>
        /// Performs the drawing of the object by dispatching the drawing of the frame to the GUI thread
        /// </summary>
        /// <param name="skeletalData">the object with new coordinates to be drawn</param>
        /// <returns>the result value for success or failure</returns>
        private int ProcessNewSkeletalData(SkeletalDrawingData skeletalData)
        {
            if (skeletalData == null)
            {
                return (int)ResultCodes.OutOfMemory;
            }

            skeletonToForm.Dispatcher.Invoke(DispatcherPriority.Send, TimeSpan.FromSeconds(1), new Action(
                () =>
                {
                    try
                    {
                        SkeletonFrame skeletonFrame = skeletalData.GetSkeletonFrame();

                        Brush[] brushes = new Brush[6];
                        int iSkeleton = 0;

                        brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                        brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                        brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255));
                        brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64));
                        brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255));
                        brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255));

                        skeletonToForm.Children.Clear();

                        foreach (SkeletonData data in skeletonFrame.Skeletons)
                        {
                            if (SkeletonTrackingState.Tracked == data.TrackingState)
                            {
                                Brush brush = brushes[iSkeleton % brushes.Length];

                                //Add different line segments
                                AddLineSegments(data, brush);

                                // Draw joints
                                foreach (Joint joint in data.Joints)
                                {
                                    Point jointPos = getDisplayPosition(joint);
                                    Line jointLine = new Line();
                                    jointLine.X1 = jointPos.X - 3;
                                    jointLine.X2 = jointLine.X1 + 6;
                                    jointLine.Y1 = jointLine.Y2 = jointPos.Y;
                                    jointLine.Stroke = jointColors[joint.ID];
                                    jointLine.StrokeThickness = 6;

                                    skeletonToForm.Children.Add(jointLine);

                                }
                            }

                            iSkeleton++;
                        }
                    }
                    catch
                    {

                    }
                }));

            return (int)ResultCodes.Success;
        }
        private int ProcessNewSkeletalData(SkeletalDrawingData skeletalData)
        {
            if (skeletalData == null)
            {
                return (int)ResultCodes.OutOfMemory;
            }

            transformedSkeletonToForm.Dispatcher.Invoke(DispatcherPriority.Send, TimeSpan.FromSeconds(1), new Action(
                () =>
                {
                    try
                    {
                        SkeletonFrame skeletonFrame = skeletalData.GetSkeletonFrame();

                        this.tranformedJoints.jointsDictionary = this.tranformSkeleton.TransformSkeleton(skeletonFrame);

                        Brush[] brushes = new Brush[6];
                        int iSkeleton = 0;

                        brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                        brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                        brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255));
                        brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64));
                        brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255));
                        brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255));

                        transformedSkeletonToForm.Children.Clear();

                        Brush brush = brushes[iSkeleton % brushes.Length];

                        //Add different line segments
                        AddLineSegments(this.tranformedJoints.jointsDictionary, brush);

                        // Draw joints

                        foreach (KeyValuePair<JointID, Microsoft.Research.Kinect.Nui.Vector> keyValuePair in this.tranformedJoints.jointsDictionary)
                        {
                            Joint newJoint = new Joint();

                            newJoint.ID = keyValuePair.Key;
                            newJoint.Position = keyValuePair.Value;
                            newJoint.TrackingState = JointTrackingState.Tracked;

                            Point jointPos = getDisplayPosition(newJoint);
                            Line jointLine = new Line();
                            jointLine.X1 = jointPos.X - 3;
                            jointLine.X2 = jointLine.X1 + 6;
                            jointLine.Y1 = jointLine.Y2 = jointPos.Y;
                            jointLine.Stroke = jointColors[newJoint.ID];
                            jointLine.StrokeThickness = 6;

                            transformedSkeletonToForm.Children.Add(jointLine);
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }));

            return (int)ResultCodes.Success;
        }