BackRequested event crashes the app in Windows 10 Mobile v. 1511

53 views Asked by At

I'm making web browser for UWP on all Windows versions. So, I'm noticed that when WebView navigating from YouTube site to YouTube video (when navigation not completed on that time), when I pressed the hardware back button, the app crashes. The strangest things are that this doesn't occur when the app is running from debug or release mode. Also, when the same code I write the same code on Back button of my app, the function works perfectly. Also, the same crash occurring when I'm writing some code on SystemNavigationManager.GetForCurrentView().BackRequested event no matter what. The same thing is on HardwareButtons.BackPressed. The code is:

    private void CurrentView_BackRequested(object sender, BackRequestedEventArgs e)
    {
        e.Handled = true;

        if (appView.IsFullScreenMode)
        {
            appView.ExitFullScreenMode();
        }
        else
        {
            Frame frame = Window.Current.Content as Frame;
            if (!frame.CanGoBack && currentWebView.CanGoBack)
            {
                currentWebView.GoBack(); //the real function
            }
            else
            {
                if (PivotMain.Items.Count > 1)
                {
                    CloseOneTab(PivotMain.SelectedWebViewItem);
                }
                else
                {
                    e.Handled = false;
                }
            }
        }
    }

Update 1: the app doesn't crash when WebView is set on WebViewExecutionMode.SeparateThread. But somewhy I think that it's risky ‍♂️.

0

There are 0 answers