改变调度员时间的时间间隔
changing time interval in dispatcher time
所以我正在尝试更改调度员时间的时间间隔。我试图通过使用依赖项 属性.
来更改计时器
见下面代码:
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 更改为 "fast forward":
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;
TimeInterval
依赖属性在这里没用。只需更改 DispatcherTimer 的间隔 属性:
if (TimersInterval < 1000)
{
TimersInterval += 100;
aTimer.Interval = TimeSpan.FromMilliseconds(TimersInterval);
}
...
也许你甚至不需要 TimersInterval
属性:
if (aTimer.Interval.TotalMilliseconds < 1000)
{
aTimer.Interval += TimeSpan.FromMilliseconds(100);
}
所以我正在尝试更改调度员时间的时间间隔。我试图通过使用依赖项 属性.
来更改计时器见下面代码:
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 更改为 "fast forward":
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;
TimeInterval
依赖属性在这里没用。只需更改 DispatcherTimer 的间隔 属性:
if (TimersInterval < 1000)
{
TimersInterval += 100;
aTimer.Interval = TimeSpan.FromMilliseconds(TimersInterval);
}
...
也许你甚至不需要 TimersInterval
属性:
if (aTimer.Interval.TotalMilliseconds < 1000)
{
aTimer.Interval += TimeSpan.FromMilliseconds(100);
}