-1

I created an error Logging for my WP8 Application so that whenever the application crashes, a MessageBox will show and will ask the user to send the Log File through email.

This is how I implemented it in App.xaml.cs,

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        //File Handler for Log file
        Log.write("some string here");

        MessageBoxResult result = MessageBox.Show("String", "String", MessageBoxButton.OKCancel);

        if (result == MessageBoxResult.OK) // BREAKPOINT here
        {
            EmailComposeTask emailComposeTask = new EmailComposeTask();
            emailComposeTask.Subject = "Unhandled Exception";
            emailComposeTask.Body = "Device OS Version: " + Environment.OSVersion.ToString() + "\n\n" + Log.readFile();
            emailComposeTask.To = "email@email.com";
            emailComposeTask.Show();
        }

        if (Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            Debugger.Break();
        }
    }

During debug in my device, everything works fine and was able to send the Log content to my email IF I PUT A BREAKPOINT in if (result == MessageBoxResult.OK) or any line before emailComposeTask.Show();

And if I disable the breakpoint, MessageBox shows BUT emailComposeTask won't show.

What could be the problem? Only during debug and breakpointing it works, not when I remove the breakpoint.

venerik
  • 5,766
  • 2
  • 33
  • 43
Jim.B
  • 426
  • 6
  • 14

1 Answers1

1

The UnhandledException handler is not the correct place to do what you want. Whats being done usually is store the exception info (and anything else you find useful) in ApplicationSettings and let your app die. On next launch of your app you can check for the existance of the exception in storage and if there then you can prompt the user and open the email client.

You'll find this little utility quite useful http://blogs.msdn.com/b/andypennell/archive/2010/11/01/error-reporting-on-windows-phone-7.aspx

atomaras
  • 2,468
  • 2
  • 19
  • 28