Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改调度程序时间中的时间间隔_C#_Wpf_Dispatchertimer - Fatal编程技术网

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);
}