I am trying to retrieve X and Y coordinates of a Ellipse
. The retrieving is done through a Timer and a EllapsedEventHandler
:
public void record(object sender, ElapsedEventArgs args)
{
DateTime t = args.SignalTime; // Take the time the tick was done
Point ellipseCoordiante = new Point(Canvas.GetLeft(observee.StimulyEllipse1), Canvas.GetTop(observee.StimulyEllipse1)); // Parse coordinates from StimulyWindow to service and then to thread where they will be recorded into the log file
Point controller1 = new Point(Canvas.GetLeft(observee.Pointer1), Canvas.GetTop(observee.Pointer1));
Point controller2 = new Point(Canvas.GetLeft(observee.Pointer2), Canvas.GetTop(observee.Pointer2));
string[] toWrite = new string[] { t.Ticks.ToString(), " ", watch.Elapsed.ToString(), " ", ellipseCoordiante.ToString(), " ", controller1.ToString(), " ", controller2.ToString() };
System.IO.File.WriteAllLines(logPath, toWrite);
}
My problem is that I can not retrieve the coordinates from the GUI.
I get the error
" The calling thread cannot access this object because a different thread owns it " .
I was thinking of saving the coordinates of the Ellipse in a different class each time they get modified , and the Timer can periodically acces the values to read them .
My questions are:
a) Is there a way to get the info I need directly from the GUI thread ;
b) If not , then how could I pass the Ellipse x and y position in my Canvas to the class I make