Question

I'm building a Windows Phone application that does video capture in a page and has a custom player in another page. I'm using my own custom codec so the player needs a lot of DispatcherTimer to keep track of several behaviors on the UI part and serve the movie at the good framerate in the codec part.

I'm trying to release all DispatcherTimer as I know they are CPU intensive, but even when stopping them my app is still very slow. If I press back-back then follow the flow, the speed divides by two each time. If I don't use my player, eveything is ok. And my player is only made of 3 DispatcherTimer, a FileStream and an Image box.

I feel that DispatcherTimer are still running in memory and are double-instantiated even if they are instantiated as private on the page directly.

Can I force the page to release all this stuff?

Actually I don't understand yet what is the difference between navigating to a page next to current page, or navigating back. I don't know i.e. how the page is shown again without calling InitializeComponents, so I'm mixed up about which resources to release, and which resources to keep intact.

Was it helpful?

Solution

My execution speed problem was really caused by some running DispatcherTimer, so I'll answer it to have it archived.

The solution:

  1. Ensuring that all DispatcherTimer has been instantiated directly on the page so that we can nullify them from anywhere in the code.

  2. In OnNavigatedFrom, I kill the DispatcherTimer and in OnNavigatedTo, I recreate them with myDispatcherX = new DispatcherTimer();

  3. No "temporary" timers, like "DispatcherTimer myTempTimer = new DispatcherTimer; with ((DispatcherTimer)send).Stop() in callback, as chances are that it remains in memory in an application where we navigate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top