0

Considering the following C# code:

                if (finalTextConvertTimer != null)
                {
                    if (finalTextConvertTimer.IsEnabled)
                    {
                        finalTextConvertTimer.Stop();
                    }
                    finalTextConvertTimer.Start();
                }

Is it necessary to stop the timer first? One developer here says it's not. Just looking for validation.

  • It timer exists (not disposed), then calling `Stop()` is safe without checking for anything. – Sinatr Oct 27 '14 at 15:28
  • If you want to *restart* it so it times the full Interval again, then yes. – Hans Passant Oct 27 '14 at 15:44
  • Yes, @HansPassant. The intent is to have the timer start as if it were starting for the first time. My co-worker insists that calling Start() does this anyway. – Jason P Sallinger Oct 27 '14 at 15:52
  • These kind of disputes are fairly silly when you can simply try it yourself or look [at the source code](http://referencesource.microsoft.com/#WindowsBase/src/Base/System/Windows/Threading/DispatcherTimer.cs#181). Easy to see that Start() does absolutely nothing if the timer is already enabled. – Hans Passant Oct 27 '14 at 16:12
  • Why then, would Microsoft claim the Interval is restarted? – Jason P Sallinger Oct 27 '14 at 16:17

1 Answers1

1

Apologies for not researching in MSDN first. From the method documentation (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.start(v=vs.110).aspx):

Start resets the timer Interval.

  • IF the timer is already started, then calling `Start` [does nothing](http://referencesource.microsoft.com/#WindowsBase/src/Base/System/Windows/Threading/DispatcherTimer.cs) – Sriram Sakthivel Oct 28 '14 at 06:08