tags:

views:

49

answers:

2

I think that IsEnabled = false/true is equally the same with Stop/Start method of class System.Windows.Threading.DispatcherTimer Am I right?

[EDIT] Start() : begin timer with a full interval countdown. IsEnabled = false : pause the timer, the interval countdown remains. IsEnabled = true : resume the timer & continue with the last used interval countdown. Stop() : stop the timer, will the interval countdown reset?

A: 

Yes they are the same: http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.isenabled.aspx

spinon
Sorry I should have clarified. I was answering whether IsEnabled setting would have the same result as Start/Stop in regards to starting/stopping the timer
spinon
+4  A: 

Considering that Start/Stop toggles the IsEnabled property, your assumption is close.

Start/Stop differs as the Interval is reset, where as just toggling the IsEnabled will not reset the Interval.

From MSDN:

Setting IsEnabled to false when the timer is started stops the timer.

Setting IsEnabled to true when the timer is stopped starts the timer.

Start sets IsEnabled to true.

Start resets the timer Interval.

EDIT: What I mean by the interval being reset is not the Interval property itself, but the background interval that determines how long until the next tick event is fired.

Eg. If you have an interval of 1000ms and you stop/disable it if with 250ms to run (it's run for 750ms), this is the result depending on how you start it again.

  • If you start it with Start(), then the passed interval will be reset back to 0 and it will be 1000ms before the Tick event is raised.
  • If you re-enable it with IsEnabled = true then it will continue from it's current location and the Tick event will be raised in 250ms.

I hope this clarifies it for you.

Alastair Pitts
@Alastair Pitts: What happens with the Interval if it is reseted? At the moment, I think when calling Start/Stop, the Interval value (int) doesn't change.
Nam Gi VU
Not the interval value itself, but the background interval. I've updated my answer to answer this.
Alastair Pitts
Thanks! It's quite clear now except what happens when we call Stop()? Will the background interval reseted?
Nam Gi VU
The reset occurs the `Start()` is called. I would surmise (although I haven't tested) that if you called `Stop()` then `IsEnabled = true` that it would just continue, rather than reset.
Alastair Pitts