我将数据保存在隔离存储中,但是当我重新启动手机时,我无法从那里读取这些数据。隔离存储为空。为什么?
如果我不关闭手机一切正常
这是我的代码:
using (Stream file = IsolatedStorageHelper.OpenFile(USER_ACCOUNT_FILE, fileMode.Create))
{
if (null != file)
{
try
{
XDocument xml = new XDocument();
XElement root = new XElement("userAccount");
root.Add(new XAttribute("FirstName", this._firstName));
root.Add(new XAttribute("LastName", this._lastName));
root.Add(new XAttribute("ID", this._id));
root.Add(new XAttribute("Sex", this._sex));
xml.Add(root);
// save xml data
xml.Save(file);
}
catch
{
}
}
}
在隔离存储中创建文件的功能
static public IsolatedStorageFileStream OpenFile(string aFilename, FileMode mode)
{
IsolatedStorageFileStream res = null;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
res = new IsolatedStorageFileStream(aFilename, mode, FileAccess.ReadWrite, isoStore);
}
catch (Exception exc)
{
if ((null != (exc as IsolatedStorageException)) &&
(FileMode.Open != mode) &&
(true == createPathOnIsolatedStorage(isoStore,aFilename)) )
{
try
{
res = new IsolatedStorageFileStream(aFilename, mode, isoStore);
}
catch
{
}
}
}
}
return res;
}