title: how to debug app in windows phone 7 that is not launched from visual studios
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>is there a setting i need to set so that hitting the home button doesn't stop debugging?</p>
  
  <p>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. </p>
  
  <p>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?</p>
  
  <p>a sample code of how i handle tombstoning is as follows.</p>
  
  <pre><code>protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
  {
   if(NavigationMode.Back != e.NavigationMode)
   {
    try 
    {
     PhoneApplicationService.Current.State["token"] = myMvvM;
    } 
    catch(Exception ex) 
    { 
     Debug.WriteLine(ex.ToString()); 
    }
   }
  }
  </code></pre>
  
  <p>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).</p>
  
  <pre><code>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();
   }
  }
  </code></pre>