DispatcherTimer doesn't allow event subscription after timer is started
Last post 03-27-2008 6:37 AM by fkruesch. 2 replies.
Sort Posts:
03-25-2008 5:21 PM
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

 

--
Florian Kruesch | MCAD
rss: www.planet-xaml.net/index.rss
www: xaml-kru.com
Silverglobe - an open source 3D globe.

fkruesch

Loading...
Joined on 03-20-2007
Düsseldorf, Germany
Posts 20
03-27-2008 4:24 AM
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.

Allen Chen – MSFT

Loading...
Joined on 03-16-2007
Posts 1,566
03-27-2008 6:37 AM
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!

--
Florian Kruesch | MCAD
rss: www.planet-xaml.net/index.rss
www: xaml-kru.com
Silverglobe - an open source 3D globe.

fkruesch

Loading...
Joined on 03-20-2007
Düsseldorf, Germany
Posts 20
Page view counter