帮助我的应用程序有时会在运行时冻结 [英] Help My app freeze sometimes when is running

查看:64
本文介绍了帮助我的应用程序有时会在运行时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用主页中列表项的自定义控件来创建所有媒体内容的精美列表。问题是当我运行应用程序冻结一段时间(不多但可以看到控件消失并显示默认内容
名称为"TextBox"等),这使我的应用程序看起来不那么善于"用户体验"。例如,在这段代码中,我在'OnNavigateTo'中加载了方法来创建项目......

 public void CreateAlbumItemList()
{

for(int i = 0; i< library.Albums.Count; i ++)
{
albumItem [i] = new albumlistctrl();

albumItem [i] .albumTextBlock.Text = library.Albums [i] .Name;

albumItem [i] .artistTextBlock.Text = library.Albums [i] .Artist.Name;

if(library.Albums [i] .HasArt)
{
var albumArtStream = library.Albums [i] .GetAlbumArt();
BitmapImage albumArtImg = new BitmapImage();
albumArtImg.SetSource(albumArtStream);
albumItem [i] .AlbumImage.Source = albumArtImg;
}
else
{
BitmapImage albumArtImg2 = new BitmapImage(); // MusicPlayer; component
var albumArt = Application.GetResourceStream(new Uri(" Background。) png",UriKind.Relative));
albumArtImg2.SetSource(albumArt.Stream);
albumItem [i] .AlbumImage.Source = albumArtImg2;
}
}

AlbumsListBox.ItemsSource = albumItem;
}

和每个类别的项目相同


我将此方法用于整个应用程序我已经厌倦了写了很多"for i's"。和"if's"。这是唯一的方法吗?


无论如何。如何在运行时使其更柔和?

解决方案


In通常,您可以通过减少图像的像素尺寸来提高性能,从而减少内存需求。


当然要注意管理和清理这些图像对象。尝试重用它们而不是重新创建它们。使用Debug->启动Windows Phone应用程序分析,并监视内存使用情况。


希望这有帮助,

标记


I'm using a custom controls for list items in the main page to create a beautiful list of all my media content. The problem is when I run the app freeze for a bit of seconds (not much but can see the controls disappear and appear with the default content name as "TextBox" etc.) that makes my app looks like not so good to the "user experience". for example in this code, I loaded the method inside the 'OnNavigateTo' to create the items ...

 public void CreateAlbumItemList()
        {

            for (int i = 0; i < library.Albums.Count; i++)
            {
                albumItem[i] = new albumlistctrl();

                albumItem[i].albumTextBlock.Text = library.Albums[i].Name;

                albumItem[i].artistTextBlock.Text = library.Albums[i].Artist.Name;

                if (library.Albums[i].HasArt)
                {
                    var albumArtStream = library.Albums[i].GetAlbumArt();
                    BitmapImage albumArtImg = new BitmapImage();
                    albumArtImg.SetSource(albumArtStream);
                    albumItem[i].AlbumImage.Source = albumArtImg;
                }
                else
                {
                    BitmapImage albumArtImg2 = new BitmapImage();//MusicPlayer;component
                    var albumArt = Application.GetResourceStream(new Uri("Background.png", UriKind.Relative));
                    albumArtImg2.SetSource(albumArt.Stream);
                    albumItem[i].AlbumImage.Source = albumArtImg2;
                }
            }

            AlbumsListBox.ItemsSource = albumItem;
        }

and the same thing for items like for each category

I use this method for entire app so much that I'm tired to write a lot of "for i's" and "if's". Is this the only way to do that?

anyway. how can I do to make it more soft at runtime?

解决方案

Hi,

In general you might be able to increase performance by reducing the pixel dimensions of your images, which reduces memory demand.

Be careful of course regarding management and clean up of those image objects. Try to reuse them instead of recreating them. Use Debug->Start Windows Phone Application Analysis, and monitor memory usage.

Hope this helps,
Mark


这篇关于帮助我的应用程序有时会在运行时冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆