How to handle 5.2 Performance and Resource Management issue?

Recently, I came across 5.2 Performance and Resource Management issue. This is problem because you do not really get whole lots of direction as to what is wrong with your application. So here is basic tips to troubleshoot this issue very quickly.

1) Check your tombstoning and make sure it is quick and you are not saving large data back and forth into the isolated storage

2) MAKE SURE you dispose everything specially any type of streams. This was in fact one of my issue with one of the my app. Below is the sample code that fixed my app issue.

Problem Code:

public void PlaySound(string sound)

{

  using (Stream stream = TitleContainer.OpenStream(sound))

  {

    AnimalSoundEffect = SoundEffect.FromStream(stream);

    FrameworkDispatcher.Update();

    AnimalSoundEffect.Play();

  }

}

 

Fix Code:

public void PlaySound(string sound)

{

    Stream stream = null;

    try

    {

        stream = TitleContainer.OpenStream(sound);

        AnimalSoundEffect = SoundEffect.FromStream(stream);

        FrameworkDispatcher.Update();

        AnimalSoundEffect.Play();

    }

    catch (Exception ex)

    {

        LogDto logDto = new LogDto();

        logDto.Message = ex.Message;

        logDto.Title = “Sound Failure”;

        ToeTapzServiceViewModel.Instance.LogException

        (Settings.Instance.CurrentTrackingAppId, “Pull And Speak” , logDto);

    }

    finally

    {

        // Make sure to Dispose this stream or the garbage collector

        // takes FOREVER to kill it and the app loads REALLY slow on the next launch

        if (stream != null)

        {

            stream.Dispose();

        }

    }

}

 

Notice the problem code above. I do infact disposes my stream using “Using” but that in fact did not work for me so I had to result to good old fasion style using finally to dispose. There must be delay how “Using” disposes resources vs. actually calling Dispose method directly.

About toetapz

Henry Lee is founder of NewAgeSolution.Net and is passionate about the technology. He is also the author of the book Beginning Windows Phone 7 Development 2nd from Apress (http://www.apress.com/9781430235965). He works with various Fortune 500 companies delivering mobile applications and rich internet applications. He recently formed start-up company called ToeTapz.com focusing his energy on delivering mobile applications in Windows Phone 7, Android and iPhone. In his spare time, he dedicates his effort to help his .NET community by delivering sessions at the technology events. He enjoys talking with other technologist about current trends in the technology and sharing business insights with fellow colleagues. Often you will find Henry at local cigar bar enjoying a cigar and a drink trying to come up with next big mobile application.
This entry was posted in Marketplace Certification, Windows Phone 7 and tagged , . Bookmark the permalink.

2 Responses to How to handle 5.2 Performance and Resource Management issue?

  1. Pingback: How to handle Application test failed – Error: 6.5 Applications that Play Music? | Toetapz's Blog

  2. Ashish Gupta says:

    In My xna Game there is a background music for that whenever i entered in my game i gave one alert message box in which its asking you want to stop media player or not?.If u click yes then media player will stop and ur background sound will be play but if user click volume increase or decrease button “mini-playback controls” will come.And if user click play button then both the sounds will mix.There is any solution to hide or remove or quit mini-playback controls.from volume bar.

    OR

    U Can Tell Me How we can disable Zune media player from Volume Bar When ever we are in Xna Game And we click volume increase or decrease button.Or we Can Disable Zune Media Player when ever we are inside our game

    Thank U

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s