所以我试图改变调度员时间的时间间隔。我试图通过使用依赖属性来更改计时器。
见下面的代码:
public static readonly DependencyProperty TimeProperty = DependencyProperty.Register("TimeInterval", typeof(int), typeof(MainWindow));
private int TimersInterval = 200;
private int TimeInterval
{
get { return (int)GetValue(TimeProperty); }
set { SetValue(TimeProperty, TimersInterval); }
}
单击按钮“快进”时,我尝试更改TimersInterval:
if (TimersInterval <1000)
{
TimersInterval += 100;
}
else
{
MessageBox.Show("Not Legit");
}
TimersInterval发生了变化,但定时器间隔似乎没有增加。
感谢您的帮助!
编辑(抱歉忘记添加此内容):
aTimer = new System.Windows.Threading.DispatcherTimer();
aTimer.Interval = new TimeSpan(0, 0, 0, 0, TimersInterval);
TimerEvent = (s, t) => onTimedEvent(sender, t, newParticle, newEnvironment);
aTimer.Tick += TimerEvent;
答案 0 :(得分:2)
此处TimeInterval
依赖项属性无用。只需更改DispatcherTimer的Interval属性:
if (TimersInterval < 1000)
{
TimersInterval += 100;
aTimer.Interval = TimeSpan.FromMilliseconds(TimersInterval);
}
...
也许您甚至不需要TimersInterval
属性:
if (aTimer.Interval.TotalMilliseconds < 1000)
{
aTimer.Interval += TimeSpan.FromMilliseconds(100);
}