C# 不受限制地从IsolatedStorage获取数据

C# 不受限制地从IsolatedStorage获取数据,c#,wpf,isolatedstorage,C#,Wpf,Isolatedstorage,我尝试测试wpf应用程序的隔离存储,我希望可以从两个应用程序中为同一个隔离存储获取数据et InsertData。我尝试了不同的getStore(…),但没有工作 IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly, null, null); private static void LoadData()

我尝试测试wpf应用程序的隔离存储,我希望可以从两个应用程序中为同一个隔离存储获取数据et InsertData。我尝试了不同的getStore(…),但没有工作

 IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly, null, null);


private static void LoadData()
    {
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly, null, null);

        if (isoStore.GetFileNames(filename).Length == 0)
        {
            // File not exists. Let us NOT try to DeSerialize it.        
            return;
        }

        // Read the stream from Isolated Storage.    
        Stream stream = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, isoStore);
        if (stream != null)
        {
            try
            {
                // DeSerialize the Dictionary from stream.            
                IFormatter formatter = new BinaryFormatter();
                Dictionary<string, Object> appData = (Dictionary<string, Object>)formatter.Deserialize(stream);

                // Enumerate through the collection and load our Dictionary.            
                IDictionaryEnumerator enumerator = appData.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    appDictionary[enumerator.Key.ToString()] = enumerator.Value;
                }
            }
            finally
            {
                stream.Close();
            }

        }
    }
IsolatedStorageFile isoStore=IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly,null,null);
私有静态void LoadData()
{
IsolatedStorageFile isoStore=IsolatedStorageFile.GetStore(IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly,null,null);
if(isoStore.GetFileNames(filename).Length==0)
{
//文件不存在。请不要尝试反序列化它。
返回;
}
//从独立存储中读取流。
Stream Stream=新的隔离存储文件流(文件名,FileMode.OpenOrCreate,isoStore);
if(流!=null)
{
尝试
{
//从流中反序列化字典。
IFormatter formatter=新的BinaryFormatter();
字典appData=(字典)格式化程序。反序列化(流);
//列举整个集合并载入我们的词典。
IDictionaryEnumerator enumerator=appData.GetEnumerator();
while(枚举数.MoveNext())
{
appDictionary[enumerator.Key.ToString()]=enumerator.Value;
}
}
最后
{
stream.Close();
}
}
}
问候,,
Matthieu

如果你仔细阅读你正在使用的技术,你就会明白为什么你不能访问其他用户的数据。。。线索就在名称中:隔离存储。从MSDN上的页面:

对独立存储的访问始终限于创建它的用户。

通过结合用户、域和程序集标识的概念,隔离存储可以通过以下方式隔离数据,每种方式都有自己的使用场景:

•按用户和组件隔离
•按用户、域和程序集进行隔离


有关更多信息,请参阅MSDN上的页面。

为什么不像预期的那样使用它呢?另外,请提供您试图修复问题的代码,并告诉我们问题出在哪里。我使用正常使用的隔离存储。什么意思?当我用单独的手势启动同一应用程序的两个实例时。如果我添加并保存其中一个的数据,那么第二个就无法获得新数据,我也不知道需要做什么才能使其正常工作。我的回答解释了我的意思。