如何在for循环中添加Dispatcher计时器?

时间:2012-07-20 05:08:07

标签: windows-phone-7

我必须在for循环中添加Dispatcher计时器。我有一个多个图钉按钮,在运行时我想在某个时间间隔内检索此图钉按钮,以便如何在我的循环中添加调度程序计时器......

我的C#代码是......

 for (int i = 0; i <= ClsGetDeviceMap.lstLongLatitude.Count - 1; i++)
                    {
                        string lat, lon;
                        lat = ClsGetDeviceMap.lstLatitude.ElementAt<string>(i).Trim();
                        lon = ClsGetDeviceMap.lstLongLatitude.ElementAt<string>(i).Trim();
                        Latitude = Convert.ToDouble(lat);
                        LongLatitude = Convert.ToDouble(lon);
                        GpsSpeed = 44.21811;

                        map1.Center = new GeoCoordinate(Latitude, LongLatitude, GpsSpeed);
                        map1.ZoomLevel = 17;
                        map1.ZoomBarVisibility = Visibility.Visible;


                        pin[i] = new Pushpin();
                        pin[i].Location = new GeoCoordinate(Latitude, LongLatitude);


                        map1.Children.Add(pin[i]);
                        myCoorditeWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                        myCoorditeWatcher.MovementThreshold = 20;


                        //DispatcherTimer newTimer = new DispatcherTimer();
                        //newTimer.Interval = TimeSpan.FromSeconds(5);
                        //// newTimer.Tick += map1.Children.Add(pin[i]);
                        //newTimer.Start();








                        var gl = GestureService.GetGestureListener(pin[i]);

                        gl.Hold += new EventHandler<GestureEventArgs>(GestureListener_Hold);
                        gl.Tap += new EventHandler<GestureEventArgs>(GestureListener_Stack_Tap);
                        myCoorditeWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myCoorditeWatcher_PositionChanged);


                    }
                    timer = new DispatcherTimer();
                    timer.Interval = TimeSpan.FromMilliseconds(5000);
                    timer.Tick += new EventHandler(timer_Tick);
                    timer.Start();
            }

1 个答案:

答案 0 :(得分:0)

newTimer.Tick += () =>
{
    map1.Children.Add(pin[i]);
    // probably you need to stop this timer after one tick
    //newTimer.Stop();
};