Windows Phone中的IsolatedStorageException

时间:2012-05-09 09:06:38

标签: windows-phone-7 stack-trace isolatedstorage

我收到了一个堆栈跟踪报告,其中显示有一个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();

如果有人能澄清这些,我将非常感激。

谢谢,

1 个答案:

答案 0 :(得分:2)

如果空间不足,对Save的调用将失败 由于我们无法看到WriteXxxxToFile()方法正在做什么,他们可能会做一些可能导致此问题的事情。

它也可能与您有多个线程试图访问设置或应用程序关闭或逻辑删除但您的保存方法耗时太长的问题有关。

确定真正原因的最佳方法是添加一些处理来支持调用WriteToIsolatedStorage()引发此类异常的情况,然后根据您的应用/需求进行记录和报告。< / p>

关于Remove,根据MSDN

  

“这种方法不可撤销地删除了整个孤立的存储空间   当前用户的应用程序及其所有目录和文件。“