Windows phone 7 是否可以有不同的隔离存储设置。应用程序设置?

Windows phone 7 是否可以有不同的隔离存储设置。应用程序设置?,windows-phone-7,serialization,isolatedstorage,application-settings,background-agent,Windows Phone 7,Serialization,Isolatedstorage,Application Settings,Background Agent,我的问题是,我对应用程序设置所做的更改似乎没有在AudioPlayerAgent应用程序设置中更新,这应该是相同的 我的程序如下所示: 在OnNavigatedTo中的MainPage.xaml.cs中,我正在创建两个音频文件数组 Audio[] aud = new Audio[2]; Audio[] aud1 = new Audio[2]; aud[0] = new Audio(new Uri("1.mp3", UriKind.Relative), "

我的问题是,我对应用程序设置所做的更改似乎没有在AudioPlayerAgent应用程序设置中更新,这应该是相同的

我的程序如下所示:

在OnNavigatedTo中的MainPage.xaml.cs中,我正在创建两个音频文件数组

Audio[] aud = new Audio[2];
Audio[] aud1 = new Audio[2];

aud[0] = new Audio(new Uri("1.mp3", UriKind.Relative), 
                   "Test1", 
                   "Test1",
                   new Uri("Images/Covers/0000000018724345_256x256_large.jpg",                       UriKind.Relative));

aud[1] = new Audio(new Uri("2.mp3", UriKind.Relative), 
                   "Test2", 
                   "Test2",
                   new Uri("Images/Covers/0000000018698018_256x256_large.jpg", UriKind.Relative));

aud1[0] = new Audio(new Uri("3.mp3", UriKind.Relative), 
                   "Test3", 
                   "Test3",
                   new Uri("Images/Covers/0000000018465020_256x256_large.jpg", UriKind.Relative));

 aud1[1] = new Audio(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute),
                   "Episode 29",
                   "Windows Phone Radio",
                   new Uri("Images/Covers/0000000018844939_256x256_large.jpg", UriKind.Relative));
然后,我将其中一个数组保存在ApplicationSettings中

IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud;
IsolatedStorageSettings.ApplicationSettings.Save();
然后我关闭并启动BackgroundAudioPlayer

BackgroundAudioPlayer.Instance.Close();
BackgroundAudioPlayer.Instance.Play();
在我的AudioPlayer中,我正在加载以前保存的应用程序设置,这些设置工作正常

Audio[] aud;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<Audio[]>("tracklist", out aud);
然后在我的AudioPlayer中再次加载值。我的应用程序设置中仍然有旧值,AudioPlayerAgent和主页都应该使用相同的应用程序设置,对吗?事实上,它第一次被保存并可供AudioPlayerAgent使用,那么我遗漏了什么呢

我的音频课看起来像这样

[DataContractAttribute] 
public class Audio
{
    [DataMember]
    public Uri TrackUrl { get; set; }

    [DataMember]
    public string Title { get; set; }

    [DataMember]
    public string Artist { get; set; }

    [DataMember]
    public Uri CoverURL { get; set; }

    public Audio(Uri trackUrl, string title, string artist, Uri coverUrl)
    {
        TrackUrl = trackUrl;
        Title = title;
        Artist = artist;
        CoverURL = coverUrl;
    }
} 

我感觉MusicLayerAgent位于另一个程序集/dll中。如果这样做,则可以解释问题,因为每个程序集都有自己的独立存储。如果它们在同一个组件中,我不知道为什么这样做行不通,因为我自己在几乎所有的手机应用程序中都是这样做的。这是我读过的关于独立存储的最好的读物。如果有什么我希望链接是一个良好的阅读

我不明白隔离存储是如何被束缚在手机上工作的。PC应用程序中的同一命名空间具有显式作用域属性,因此您至少可以知道是否存在单独的父文件夹


如果不能通过简单地将所有文件从一个项目加载到另一个项目来将这两个项目合并为一个项目,至少可以向其中一个项目添加一个类或方法,该类或方法从IsolatedStorage加载该类并返回一个实例,然后从另一个项目调用该类,并添加引用(在解决方案资源管理器的References文件夹中)到第二个项目中的第一个项目,以便可以调用它

我也面临同样的问题。在我看来,隔离的存储设置有点“缓存”到静态的东西中。也就是说,在后台和前台进程都运行之前,它们都将使用自己版本的IsolatedStorageSettings。 深入了解原始代码,我发现以下内容:

public sealed class IsolatedStorageSettings : ...
{
    private static IsolatedStorageSettings s_appSettings;
    ...
    public static IsolatedStorageSettings ApplicationSettings
    {
        get
        {
            if (IsolatedStorageSettings.s_appSettings == null)
            {
                IsolatedStorageSettings.s_appSettings = new IsolatedStorageSettings(false);
            }
            return IsolatedStorageSettings.s_appSettings;
        }
    }
    ...
    private IsolatedStorageSettings(bool useSiteSettings)
    {
        if (useSiteSettings)
        {
            throw new NotSupportedException();
        }
        this._appStore = IsolatedStorageFile.GetUserStoreForApplication();
        this.Reload();
    }
在这里您可以看到,在方法重载中,每个进程(作为静态变量)实际上只加载一次IsolatedStorageSettings。 通过查看代码,我没有发现调用Reload的其他地方

我可以建议每个面临同样问题的人使用“自己的”设置存储在AudioAgent和应用程序之间共享动态数据(正如PhiliiIpp在他的期末报告中所说)


据我所知,最佳做法是使用AudioTrack.Tag属性。

在再次保存之前,您是否尝试过执行IsolatedStorageSettings.ApplicationSettings.Clear()操作?是的,当我在主页中执行清除操作时,MusicLayerAgent中仍有旧值。如果我清除了MusicLayerAgent中的值,那么下次我尝试阅读时就没有值了。嗨,PhiliiiIpp,你设法解决了这个问题吗?我在我的WP8应用程序中也有它,即使在您讨论了“已接受的答案”之后也没有任何帮助(我在解决方案中做了第三个项目,其中有一个类负责与isostorage交互,但没有任何帮助)。嘿,那是很久以前的事了,但就我记忆所及,制作另一个项目并不能解决它,因为如下所述,它将被打包到另一个组件中。我最终将设置写入文件并从中读取(XmlSerializer)。好吧,这可能是问题所在,我在不同的项目中有这些设置,当我右键单击项目->属性并将两个项目中的程序集名称更改为相同时,应用程序将不再启动。我如何将它们放在同一个程序集中?可能另一种方法是编写一个类,该类可供另一个项目使用,该项目从1个项目的独立存储中进行读写,这是我过去采用的方法。是的,我目前的方法是在这两者之间使用序列化程序从文件中读取值,这也很好。但我仍然无法理解隔离存储设置是如何工作的。
public sealed class IsolatedStorageSettings : ...
{
    private static IsolatedStorageSettings s_appSettings;
    ...
    public static IsolatedStorageSettings ApplicationSettings
    {
        get
        {
            if (IsolatedStorageSettings.s_appSettings == null)
            {
                IsolatedStorageSettings.s_appSettings = new IsolatedStorageSettings(false);
            }
            return IsolatedStorageSettings.s_appSettings;
        }
    }
    ...
    private IsolatedStorageSettings(bool useSiteSettings)
    {
        if (useSiteSettings)
        {
            throw new NotSupportedException();
        }
        this._appStore = IsolatedStorageFile.GetUserStoreForApplication();
        this.Reload();
    }