-3
如何從Windows Phone 7應用程序獲取最後一次崩潰(異常) 我在我的應用程序中使用C#。如何從windows phone 7應用程序獲取最後一次崩潰?
如何從Windows Phone 7應用程序獲取最後一次崩潰(異常) 我在我的應用程序中使用C#。如何從windows phone 7應用程序獲取最後一次崩潰?
有些人可能會感到驚訝,但應用程序有時會崩潰。即使我的!在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)
{
}
}
}
}
一些代碼
參考你記錄他們的任何地方你自己?我不認爲WP7會記錄桌面版本。 – jAC