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
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:
fkruesch
Member
40 Points
23 Posts
DispatcherTimer doesn't allow event subscription after timer is started
Mar 25, 2008 09:21 PM | LINK
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.
Allen Chen –...
Star
14215 Points
1854 Posts
Microsoft
Re: DispatcherTimer doesn't allow event subscription after timer is started
Mar 27, 2008 08:24 AM | LINK
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.
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
Member
40 Points
23 Posts
Re: Re: DispatcherTimer doesn't allow event subscription after timer is started
Mar 27, 2008 10:37 AM | LINK
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.