2012-05-09 32 views
0

我收到了堆栈跟踪报告,其中说明存在IsolatedStorageException。windows phone中的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 ._ ç _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(); 
    } 

UPDATE:

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个独立的存储文件,我写了values.Does以下方法删除它们的所有4个?

IsolatedStorageFile storagefile = IsolatedStorageFile.GetUserStoreForApplication(); 
storagefile.Remove(); 

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

谢谢

+0

嗨,你能提供异常消息吗? –

+0

@Ashura有趣的是我不能重现崩溃。 :(我不知道是什么消息抛出 – alfah

回答

2

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

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

确定真实原因的最佳方法是添加一些处理以支持WriteToIsolatedStorage()的调用引发此类异常,然后根据您的应用程序/需求进行登录和报告。

关于Remove,按照MSDN

“这个方法不可撤销地消除了对 当前用户的应用程序和它的所有目录和文件的整个独立存储。”

+0

感谢@Matt,我已经用WriteNoteToFile函数更新了这个问题,这个报告只是在我更新了几个版本之后才出现的,它之前从来没有用过。更新写入/读取的逻辑从未被修改 – alfah

+0

因为你禁止WriteNoteToFile方法发生任何错误,所以它不会出现,我建议添加适当的错误日志和异常处理并提交更新。 –