1

i am currently working on handling tombstoning for my app. to tombstone my app, i navigate 2 pages into my app (from the first page). i then hit the home button, then i hit the back button to get back to my app. after hitting the back button, all i see is a page that says "resuming" with a progress bar. it just seems to stall.

now, when i launch the app, i launch it from visual studio to my device. but as soon as i hit the home button on the device, the debugger in visual studio quits. so when i hit the back button to get to my app, i don't get a chance to debug from visual studio any more.

is there a setting i need to set so that hitting the home button doesn't stop debugging?

also, if i try to go to my app on my device through the app listing, my app stalls with the default splash screen image. so something is definitely going wrong.

is there a process associated with the device that i can attach the debugger in visual studio to for debugging? or do i always need to launch the application from visual studio to debug?

a sample code of how i handle tombstoning is as follows.

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
 if(NavigationMode.Back != e.NavigationMode)
 {
  try 
  {
   PhoneApplicationService.Current.State["token"] = myMvvM;
  } 
  catch(Exception ex) 
  { 
   Debug.WriteLine(ex.ToString()); 
  }
 }
}

right now i don't do anything on Application_UnhandledException in App.xaml.cs. the code is left as generated (i only but Debug.WriteLine in there to view the log).

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
 //break point is placed on line right below this comment line
 Debug.WriteLine("unhandled exception sender type = " + 
  sender.GetType().FullName + ", ex = " + e.ToString());

 if (System.Diagnostics.Debugger.IsAttached)
 {
  // An unhandled exception has occurred; break into the debugger
  System.Diagnostics.Debugger.Break();
 }
}
Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
jake
  • 1,405
  • 3
  • 19
  • 33

1 Answers1

2

If you're running in debug mode, it won't quit when you click home, unless a exception occurs. It'll only quit if you exit the application, ie. press back from the first screen.

But it sounds like your tombstoning logic is throwing a exception, and you're not catching it. Have you implemented a handler for the Application.UnhandledException event? (The default App.xaml.cs templates for Visual Studio implements it)

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
  • i see that line where if forces the debugger to break. i've commented that line. i've also added a Debug.WriteLine statement to log the arguments (object sender, ApplicationUnhandledExceptionEventArgs e). the "strange" thing is that when i uncomment that line, i no longer get the problem i observed above. i think this problem is intermittent and going to be hard to reproduce. – jake Jul 26 '11 at 12:35
  • A standard implementation looks like this, where you use Debug.Break to break, so you can analyse the ApplicationUnhandledExceptionEventArgs containing the exception that caused the error. https://bitbucket.org/Windcape/goto-con/src/a5c9be4219b6/GotoCon/App.xaml.cs#cl-66 – Claus Jørgensen Jul 26 '11 at 12:39
  • You not handling it, would be precisely why you're not getting debug information. And that also proves that your tombstoning code is failing, most likely due to a serialization error. – Claus Jørgensen Jul 26 '11 at 12:39
  • please see the code above. i surround the line where i do save the state in a try/catch block. shouldn't i see some output there if serialization fails? – jake Jul 26 '11 at 12:55
  • Have you verified, with the debugger, that the said code is being executed at all? (The debugger should still be attached on the OnNavigatedFrom event, iirc) – Claus Jørgensen Jul 26 '11 at 12:57
  • Use the debugger then! Setting breakpoints in Visual Studio is easier. (Hint: Debug.WriteLine won't work either, if the debugger isn't attached) – Claus Jørgensen Jul 26 '11 at 13:02
  • what i'm saying is that when it breaks (whatever exception is being throw), so does the debugger's attachment from the app. i placed a breakpoint inside Application_UnhandledException and it i never hit that break point. i also put a Debug.WriteLine, and don't see those output as well. – jake Jul 26 '11 at 13:26