C# 更改调度程序时间中的时间间隔
因此,我尝试更改调度程序时间的时间间隔。我尝试使用依赖属性更改计时器 请参见下面的代码:C# 更改调度程序时间中的时间间隔,c#,wpf,dispatchertimer,C#,Wpf,Dispatchertimer,因此,我尝试更改调度程序时间的时间间隔。我尝试使用依赖属性更改计时器 请参见下面的代码: public static readonly DependencyProperty TimeProperty = DependencyProperty.Register("TimeInterval", typeof(int), typeof(MainWindow)); private int TimersInterval = 200; private int TimeInterval
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); }
}
我尝试将单击按钮时的时间间隔更改为“快进”:
TimeInterval
依赖项属性在这里是无用的。只需更改Dispatchermer的Interval属性:
if (TimersInterval < 1000)
{
TimersInterval += 100;
aTimer.Interval = TimeSpan.FromMilliseconds(TimersInterval);
}
...
你是否尝试过停止计时器,然后再次启动它?是的,仍然不起作用:/你可以添加DP的注册吗?我已经添加了注册@erNodeWeerYou's my hero:)Tks!
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;
if (TimersInterval < 1000)
{
TimersInterval += 100;
aTimer.Interval = TimeSpan.FromMilliseconds(TimersInterval);
}
...
if (aTimer.Interval.TotalMilliseconds < 1000)
{
aTimer.Interval += TimeSpan.FromMilliseconds(100);
}