将DispatcherTimer.Start()计为tick [英] Making DispatcherTimer.Start() count as a tick

查看:123
本文介绍了将DispatcherTimer.Start()计为tick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF中有一个调度员,我发现它非常令人沮丧,因为当我开始()它时,它不算作一个滴答声。目前它的功能是这样的:



开始()[间隔]

[tick]

[interval]

[tick]

...

我怎么能这样做,所以Start()计为勾号并开始立即让它像这样工作?:

开始()[勾]

[间隔]

[tick]

否则我必须复制在启动计时器之前在tick事件中发生的事情,这不是非常有效,因为我只是想让计时器立即启动。

I have a dispatchertimer in WPF and I am finding it very frustrating because when I Start() it, it does not count as a tick. At the moment it's functionality is like this:

Start() [interval]
[tick]
[interval]
[tick]
...
How can I make it so the Start() counts as a tick and it starts immediately and make it work like this?:
Start() [tick]
[interval]
[tick]
Otherwise I have to duplicate what happens in the tick event before starting the timer which is not very efficient as I just want the timer to start immediately.

推荐答案

我建议不要忽视这个微不足道的问题。当然,永远不要复制任何东西。创建一个单独的方法,从tick处理程序调用,并在start时调用它。这将是一个非常干净的方法。



-SA
I suggest not to break your head over the insignificant problem. Of course, never duplicate anything, ever. Create a separate method to be called from the tick handler and also call it at start. It would be a perfectly clean approach.

—SA


我所做的只是打电话启动计时器后的tick事件。我知道它可能不是最好的方式,但它适用于我需要的东西。
All I did was just call the tick event after starting the timer. I know its probably not the best way but it worked for what I needed.


这篇关于将DispatcherTimer.Start()计为tick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆