Share via


DispatcherTimer.Interval 属性

定义

获取或设置计时器刻度之间的时间段。

public:
 property TimeSpan Interval { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan Interval { get; set; }
member this.Interval : TimeSpan with get, set
Public Property Interval As TimeSpan

属性值

刻度之间的时间段。 默认值为“00:00:00”。

例外

interval 小于 0 或大于 Int32.MaxValue 毫秒。

示例

以下示例创建了一个 DispatcherTimer。 将创建名为 dispatcherTimer 的新DispatcherTimer对象。 事件处理程序 dispatcherTimer_Tick 将添加到 事件中 TickInterval使用 TimeSpan 对象将 设置为 1 秒。

//  DispatcherTimer setup
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
dispatcherTimer.Start();
'  DispatcherTimer setup
dispatcherTimer = New Threading.DispatcherTimer()
AddHandler dispatcherTimer.Tick, AddressOf dispatcherTimer_Tick
dispatcherTimer.Interval = New TimeSpan(0,0,1)
dispatcherTimer.Start()

注解

不保证计时器在时间间隔发生时准确执行,但保证它们不会在时间间隔发生之前执行。 这是因为 DispatcherTimer 操作与其他操作一样放在队列上 DispatcherDispatcherTimer执行操作时依赖于队列中的其他作业及其优先级。

适用于