Skip to main content

Microsoft Silverlight

DispatcherTimer doesn't allow event subscription after timer is startedRSS Feed

(0)

fkruesch
fkruesch

Member

Member

38 points

22 Posts

DispatcherTimer doesn't allow event subscription after timer is started

In the following code snippet. the _timer_Tick event will never be called. Obviously
Silverlight doesn't allow to subscribe to a DispatcherTimer once it runs.

_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromSeconds(0.5);
_timer.Start();
_timer.Tick +=
new EventHandler(_timer_Tick);

This is quite confusing until you figure it out...
Florian

 

Allen Chen – MSFT
Allen Ch...

Star

Star

13662 points

1,780 Posts

Re: DispatcherTimer doesn't allow event subscription after timer is started

Hi:

  Thanks for reproting this issue and sorry for confusing you so much. But it's by design and from the msdn we can see the example also attach the event before calling Start method:

http://msdn2.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx

  However it's very kind of you to point it out, which may save other's time.

Thanks again.

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

fkruesch
fkruesch

Member

Member

38 points

22 Posts

Re: Re: DispatcherTimer doesn't allow event subscription after timer is started

It is confusing, because in WPF proper you can attach an event handler once
the timer is running!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities