我必须在 for 循环中添加调度程序计时器。我有多个图钉按钮,在运行时我想在某个时间间隔内检索这个图钉按钮,所以如何在我的循环中添加调度程序计时器......
我的 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();
}