我收到了一个堆栈跟踪报告,其中显示有一个IsolatedStorageException。
“帧图像功能偏移”
0 coredll.dll xxx_RaiseException
1 mscoree3_7.dll
2 mscoree3_7.dll
3 mscoree3_7.dll
4 TransitionStub
5 System.IO.IsolatedStorage.IsolatedStorageSettings.Save
6 System.IO.IsolatedStorage.IsolatedStorageSettings.Clear
7 AppName.CycleManager.WriteToIsolatedStorage
8 AppName.SettingsPage.OnNavigatedFrom
9 Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedFrom
10 System.Windows.Navigation.NavigationService.RaiseNavigated
11 System.Windows.Navigation.NavigationService.CompleteNavigation
12 System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback
13 System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread
14 ._ c _DisplayClass4._BeginLoad_b__0
15 mscoree3_7.dll
16 mscoree3_7.dll
17 mscoree3_7.dll
18 System.Reflection.RuntimeMethodInfo.InternalInvoke
19 System.Reflection.RuntimeMethodInfo.InternalInvoke“
所以我认为WriteToIsolatedStorage()引发了异常。
public void WriteToIsolatedStorage()
{
IsolatedStorageSettings dataStorage = IsolatedStorageSettings.ApplicationSettings;
dataStorage.Clear();
dataStorage.Add("firstLaunchDate", App.LaunchedDateTime);
dataStorage.Add("weekStart", m_bWeekStart);
dataStorage.Add("iHistCount", m_iHistCount);
// All the variables i need to store
dataStorage.Add("noteCount", m_noteCount);
WriteNotesToFile();
dataStorage.Add("weightCount", m_iWeightCount);
WriteWeightToFile();
dataStorage.Add("tempCount", m_iTempCount);
WriteTempToFile();
dataStorage.Save();
}
更新
public void WriteNotesToFile()
{
if (m_noteCount > 0)
{
try
{
using (IsolatedStorageFile storagefile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storagefile.FileExists("NotesFile"))
{
using (IsolatedStorageFileStream fileStream = storagefile.OpenFile("NotesFile", FileMode.Open, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(fileStream);
for (int i = 0; i < m_noteCount; i++)
{
//writer.Write(m_arrNoteDate[i].ToShortDateString());
writer.Write(m_arrNoteDate[i].ToString("d", CultureInfo.InvariantCulture));
writer.Write(" ");
writer.Write(m_arrNoteString[i]);
writer.WriteLine("~`");
}
writer.Close();
}
}
else
{
storagefile.CreateFile("NotesFile.txt");
using (IsolatedStorageFileStream fileStream = storagefile.OpenFile("NotesFile", FileMode.Create, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(fileStream);
for (int i = 0; i < m_noteCount; i++)
{
//writer.Write(m_arrNoteDate[i].ToShortDateString());
writer.Write(m_arrNoteDate[i].ToString("d", CultureInfo.InvariantCulture));
writer.Write(" ");
writer.Write(m_arrNoteString[i]);
writer.WriteLine("~`");
}
writer.Close();
}
}
}
}
catch { }
}
}
有人能告诉我抛出异常的条件。我读到某个地方,当没有足够的空间时,会抛出这样的异常。
最后,我有4个独立的存储文件,我写了值。以下方法是否删除了所有4个文件?
IsolatedStorageFile storagefile = IsolatedStorageFile.GetUserStoreForApplication();
storagefile.Remove();
如果有人能澄清这些,我将非常感激。
谢谢,