我只想在执行函数PreCalculateAsync()后才调用计时器函数。现在,计时器每30毫秒调用一次。但是最初我想执行PreCalculateAsync函数。我该如何实现?
我的代码:
public PathAnimation(Geopath path, IntervalCallback intervalCallback, bool isGeodesic, int? duration)
{
PreCalculateAsync();
_timerId = new DispatcherTimer();
_timerId.Interval = new TimeSpan(0, 0, 0, 0, 30);
_timerId.Tick += (s, a) =>
{
if (!_isPaused)
{
if (intervalCallback != null)
{
intervalCallback(_intervalLocs[_frameIdx], _intervalIdx[_frameIdx], _frameIdx);
}
if (_frameIdx + 1 == _intervalLocs.Count())
{
_timerId.Stop();
}
_frameIdx++;
}
};
}
public delegate void IntervalCallback(BasicGeoposition loc, int pathIdx, int frameIdx);
private async void PreCalculateAsync()
{
if (_timerId != null && _timerId.IsEnabled)
{
_timerId.Stop();
}
//assign values to _intervalLocs here.
}
}