Pregunta

what i am trying to do is first find the angle of the shoulder joint till now i have managed to do that.what i wanted to do now is when the angle comes in the range between 70 and 90 a time starts for 3 sec and in each sec it should check whether the angle is still in the range if it is then show on screen ok otherwise restart the timer after displaying the message you have no completed the time limit Please please em very new to wold of C# and kinect any help in this regard will b helpful the link to an image of a problem em facing is: http://i46.tinypic.com/2nu4ygw.jpg

Please help!!

       System.Windows.Point shoul_l = this.point_toScreen(sh_left.Position, sen);
        draw.DrawText(new FormattedText(angle.ToString("0"), new 
        System.Globalization.CultureInfo("en-us"),
          System.Windows.FlowDirection.LeftToRight,
         new Typeface("Verdana"), 16,System.Windows.Media.Brushes.OrangeRed),
         new System.Windows.Point(shoul_l.X+10, shoul_l.Y +20));

        if (timer_start == false)
        {
        if (angle > 70 && angle < 90)
        {
                timer_start = true;
                timer.Interval = 2000;
                timer.Start();
                timer.Elapsed += new ElapsedEventHandler((sender, e) =>   \    
                on_time_event(sender, e, draw,shoul_l));

        }
        }


}   
void on_time_event(object sender, ElapsedEventArgs e, DrawingContext dcrt, 

 System.Windows.Point Shoudery_lefty)
 {
     --index;
     if (index != 0)
     {
         dcrt.DrawText(new FormattedText(index.ToString(), new   
      System.Globalization.CultureInfo("en-us"),
           System.Windows.FlowDirection.LeftToRight,
          new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
          new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
      //  MessageBox.Show(index.ToString());
     }
     else
     {
         timer.Stop();
     }
   }

i get an exception in this part of the code

      dcrt.DrawText(new FormattedText(index.ToString(), new   
      System.Globalization.CultureInfo("en-us"),
      System.Windows.FlowDirection.LeftToRight,
      new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
      new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
¿Fue útil?

Solución

You are trying to update a UI element from a Timer thread. This is not allowed.
You have to marshal the UI update call to the UI thread using the Dispatcher like this:

dcrt.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => 
    {
        dcrt.DrawText(new FormattedText(index.ToString(), new System.Globalization.CultureInfo("en-us"),
       System.Windows.FlowDirection.LeftToRight,
      new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
      new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
    }));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top