2012-07-20 59 views
-3

我要補充調度計時器在loop.I有多個圖釘按鈕,並在運行時我想找回一些時間間隔這個圖釘按鈕,這樣如何在我的循環添加調度計時器...如何在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(); 
      } 

回答

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