如何在暂停/恢复和恢复后强制 Windows 10 uwp webview 应用程序加载 url超时时自动重新加载 [英] How to force a Windows 10 uwp webview app to load a url after suspend / resuming & auto reload when timing out

查看:22
本文介绍了如何在暂停/恢复和恢复后强制 Windows 10 uwp webview 应用程序加载 url超时时自动重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个(简化的)c#/XAML UWP Webview 应用程序在大约 90 秒后恢复应用程序后显示一个空白页面.显示本地安全摄像头视频流网页时.当应用程序被暂停时,它似乎在大约 90 秒后超时,然后在恢复时网页视图页面为空白.为了显示下面的示例代码,我从网络搜索中随机选择了一个站点并登陆 http://www.porttampawebcam.com/.我尝试过的少数 youtube 和网络摄像头页面并没有像我的本地网络摄像头服务器那样在 1 分钟后重现超时问题.大约不活动.

This (simplified) c# / XAML UWP Webview app displays a blank page after the app is resumed after about 90+ sec. when displaying a local security cam video stream webpage. It appears to timeout after about 90 sec while the app is being suspended and then upon resuming the webview page is blank. To give the sample code below something to display, I randomly picked a site from a web search and landed on http://www.porttampawebcam.com/. The few youtube and webcam pages I've tried didn't reproduce the issue of timing out like my local web cam server does after a min. or so of inactivity.

一个按钮可以用来手动刷新/重新加载页面,但如何编码为...

A button can be used to manually refresh / reload the page, but how can it be coded to ...

A) 每次应用恢复时都强制加载 url?B) 检测到页面超时,然后根据需要重新加载?

A) Force the url to load every time the app gets resumed? B) Detect that the page has timed out and then reload as needed?

我对此做了一些研究(使用 webview 控件和 UWP 应用程序生命周期),浏览了 GitHub 上的 uwp 应用程序,并在应用程序的其他几个部分取得了进展,但还没有弄清楚这两点的工作解决方案.

I've done a bit of research on this (using the webview control & UWP application lifecyles), browsed uwp apps on GitHub, and have made progress on several other parts of the app, but have yet to figure out a working solution on these two points.

应用是使用 Visual Studio 2015 中的空白应用(通用 Windows)模板构建的.

App was built using the Blank App (Universal Windows) template in Visual Studio 2015.

XAML:

Mainpage.xaml

<Page
    x:Class="WVMinimal.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" ></RowDefinition>
        <RowDefinition Height="auto" ></RowDefinition>

    </Grid.RowDefinitions>
    <WebView Name="WV" Source="http://www.porttampawebcam.com"/>
    </Grid>
</Page>

c#:

Mainpage.xaml.cs


using Windows.UI.Xaml.Controls;

    // The Blank Page item template is documented at     https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

    namespace UWPWebviewTest5
    {
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {

        public MainPage()
        {
            this.InitializeComponent();

        }


}

推荐答案

我知道这有点晚了,可能不是 100% 回答您的问题,但也许您可以尝试像这样刷新 WebView 内容:

I know it's a bit late and maybe not 100% answering your question but maybe you could try to refresh the WebView content like this:

await WebView.ClearTemporaryWebDataAsync();
yourWebView.Navigate(new Uri("https://www.yourUri.com"));

这篇关于如何在暂停/恢复和恢复后强制 Windows 10 uwp webview 应用程序加载 url超时时自动重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆