Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

DispatcherTimer doesn't allow event subscription after... RSS

2 replies

Last post Mar 27, 2008 10:37 AM by fkruesch

(0)
  • fkruesch

    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

     

  • Allen Chen – MSFT

    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.

    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

    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!