0

The below code works when I debug the app. internet explorer loads the uri. No problem there. But when I stop debugging and try it out, the internet explorer does open up with the URI loaded, but the app isn't running anymore. It just stops

private void appBtnOpenInIE_Click(object sender, RoutedEventArgs e)
{
    var uri = readingWebView.Source;
    var success = Windows.System.Launcher.LaunchUriAsync(uri);
}

appBtnOpenInIE is the SecondaryCommand from which I am trying to load the URI in Internet Explorer readingWebView is the WebView control I have loaded on the xaml page which has the web page loaded

Note that I am using the exact 2 lines of code in another case where I am loading a URI based on the click of a HyperlinkButton and that works fine too. The app continues to run in the background and Internet Explorer has the URI loaded

Piyush Raja
  • 49
  • 1
  • 5
  • 2
    Once you fire Internet Explorer, your app gets *Suspended*, please take a look at [lifecycle of apps](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh464925.aspx). It's working little different in debug mode, where the suspension [must be invoked](http://stackoverflow.com/questions/24103101/suspending-event-not-raising-on-windows-phone-8-1-using-winrt/24103734#24103734) – Romasz Nov 16 '14 at 15:27
  • But the same line of code works fine when I use it from the HyperlinkButton. Debugging or not, it works as expected from the hyperlink and not from the command bar. And it doesn't suspend when its running live. It just stops – Piyush Raja Nov 16 '14 at 16:37
  • What do you mean that 'app is running live' and 'app stops'? You have some kind of a timer or other? What do you expect? The app should be suspended within few seconds after you send it to the 'background'. – Romasz Nov 16 '14 at 17:52
  • When I say live, I mean without the debugger. And when I say app stops, I mean its terminated, not suspended. The expected behavior is that it gets suspended and internet explorer opens. What's happening in my case is that internet explorer opens, but the app doesn't suspend, it terminates. – Piyush Raja Nov 16 '14 at 18:41
  • It makes it more clear. I suspect that the suspending event is raised and it throws an exception. Are you subscribing to *Suspending* event? Can you try to debug this event (the link from first post)? – Romasz Nov 16 '14 at 18:56
  • I've debugged this event. But with the debugger attached, IE opens & app suspends. So that's as expected. Is there anything more I should look at. When I run without debug, IE opens & app terminates. I'll try handling the suspended event and get back to you – Piyush Raja Nov 16 '14 at 20:02
  • 1
    @Romasz you were right. When moving from Page1 to Page2, I was passing an object. The suspension manager wasn't able to serialize that object in the Suspending event handler which was causing the app to terminate. Thanks for the help! – Piyush Raja Nov 17 '14 at 04:58

1 Answers1

2

Based on the help provided by @Romasz , here is the solution i found

When moving from Page1 to Page2, I was passing an object. The suspension manager wasn't able to serialize that object in the Suspending event handler which was causing the app to terminate. So, instead of passing the object type, I passed a primitive type (int) and it worked without errors

Piyush Raja
  • 49
  • 1
  • 5