2013-11-21 2 views

답변

0

놀랍지 만 응용 프로그램이 충돌하는 경우가 있습니다. 심지어 내 꺼야! WP7에서 애플 리케이션이 처리되지 않은 예외를 가지고있을 때 그것은 운영체제에 의해 죽게되고 당신 개발자는 현명하지 않을 것입니다. 그러나 당신은 당신의 애플 리케이션이 죽었을 때 알고 싶은 경우, 이상적 왜 여기 here

namespace YourApp 
{ 
    public class LittleWatson 
    { 
     const string filename = "LittleWatson.txt"; 

     internal static void ReportException(Exception ex, string extra) 
     { 
      try 
      { 
       using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        SafeDeleteFile(store); 
        using (TextWriter output = new StreamWriter(store.CreateFile(filename))) 
        { 
         output.WriteLine(extra); 
         output.WriteLine(ex.Message); 
         output.WriteLine(ex.StackTrace); 
        } 
       } 
      } 
      catch (Exception) 
      { 
      } 
     } 

     internal static void CheckForPreviousException() 
     { 
      try 
      { 
       string contents = null; 
       using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        if (store.FileExists(filename)) 
        { 
         using (TextReader reader = new StreamReader(store.OpenFile(filename, FileMode.Open, FileAccess.Read, FileShare.None))) 
         { 
          contents = reader.ReadToEnd(); 
         } 
         SafeDeleteFile(store); 
        } 
       } 
       if (contents != null) 
       { 
        if (MessageBox.Show("A problem occurred the last time you ran this application. Would you like to send an email to report it?", "Problem Report", MessageBoxButton.OKCancel) == MessageBoxResult.OK) 
        { 
         EmailComposeTask email = new EmailComposeTask(); 
         email.To = "[email protected]"; 
         email.Subject = "YourAppName auto-generated problem report"; 
         email.Body = contents; 
         SafeDeleteFile(IsolatedStorageFile.GetUserStoreForApplication()); // line added 1/15/2011 
         email.Show(); 
        } 
       } 
      } 
      catch (Exception) 
      { 
      } 
      finally 
      { 
       SafeDeleteFile(IsolatedStorageFile.GetUserStoreForApplication()); 
      } 
     } 

     private static void SafeDeleteFile(IsolatedStorageFile store) 
     { 
      try 
      { 
       store.DeleteFile(filename); 
      } 
      catch (Exception ex) 
      { 
      } 
     } 
    } 
} 
관련 문제