我想检索Ellipse
的X和Y坐标。检索通过定时器和做了EllapsedEventHandler
:从主GUI线程检索信息
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);
}
我的问题是,我不能检索从GUI的坐标。
我得到的错误
“因为不同的线程拥有它调用线程不能访问该对象”。
我正在考虑在每次修改时将Ellipse的坐标保存在不同的类中,Timer可以定期访问这些值以读取它们。
我的问题是:
一)有没有办法让我直接从需要GUI线程的信息;
b)若没有,那么我怎么能传递我的画布椭圆x和y位置I类做
你使用什么Timer类? –
是的,只需使用[DispatcherTimer](https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v = vs.110).aspx) – GazTheDestroyer
我正在使用系统。 Timers.Timer。 – BigBadCoder