locked
Best way Disposing / Stoping DispatcherTimer when you leave a Page

    Question

  • Hello,
    I would like to know whats the best way of disposing DispatcherTimer. So here is my scenario:

    I 'm using DispatcherTimer to handle some events on every page. When I leave a page the DispatcherTimer continues to run and that is bad. DispatcherTimer is Initialized in the Page Constructor so when i return in the page it resets.

    So i though adding this code when i leave the page:

    protected override void OnNavigatedFrom(NavigationEventArgs e)
          {            
                dispatcherTimer.Stop();            
                dispatcherTimer = null;
    
                navigationHelper.OnNavigatedFrom(e);        
          }


    Should i also add GC.Collect(); after null?

    Sorry if my English is bad,

    Regards.

    Wednesday, August 06, 2014 8:25 AM

Answers

All replies