此页有问题。c#网络视图2

此页有问题。c#网络视图2,c#,winforms,webview2,C#,Winforms,Webview2,我已经在VS2019中构建了一个C#windows窗体应用程序,其中包括Webview2(最新的预发行版)来创建浏览器。应用程序加载页面并检查特定内容。如果内容不在那里,它将重新加载页面。如果内容在那里(尚未出现),它将填充一些字段并单击按钮 应用程序在一段时间内运行良好。现在,每隔一段时间,我就会在Webview2控件中看到以下内容: 此页有问题。请稍后再谈 您还可以:打开新选项卡刷新页面 错误代码:状态\u访问\u冲突 我在调试模式下运行应用程序,试图捕获错误。没有例外。如果我在Webvie

我已经在VS2019中构建了一个C#windows窗体应用程序,其中包括Webview2(最新的预发行版)来创建浏览器。应用程序加载页面并检查特定内容。如果内容不在那里,它将重新加载页面。如果内容在那里(尚未出现),它将填充一些字段并单击按钮

应用程序在一段时间内运行良好。现在,每隔一段时间,我就会在Webview2控件中看到以下内容:

此页有问题。请稍后再谈

您还可以:打开新选项卡刷新页面

错误代码:状态\u访问\u冲突

我在调试模式下运行应用程序,试图捕获错误。没有例外。如果我在
Webview2
控件的
ContentLoading
事件中放置断点,则在看到此错误页面之前,它不会触发。我不知道是什么触发了它,也不知道如何阻止它

在Form_load上,我调用以下命令:

async void checksites()
{
    await wv2Dig.EnsureCoreWebView2Async();
    wv2Dig.CoreWebView2.Navigate(strURL);
}
ContentLoading
将调用下面的函数,该函数尝试在页面加载时检查内容,以便在页面完全加载之前做出决定。现在它只是触发了我们不想要的按钮。代码如下:

async Task DigPageCheck()
        {
            iDigCount += 1; //count of number of checks
            txtDig.Text = iDigCount.ToString(); //display count

            string strResult = await wv2Dig.CoreWebView2.ExecuteScriptAsync("document.documentElement.innerHTML;");  
            //get innerHTML
            strResult = Regex.Unescape(strResult);
            strResult = strResult.Remove(0, 1);
            strResult = strResult.Remove(strResult.Length - 1, 1);
            //check for button we want
            int loc = strResult.IndexOf("btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button"); 
            //check for button we want
            int loc2 = strResult.IndexOf("btn btn-disabled btn-lg btn-block add-to-cart-button"); x
            while (loc == -1 && loc2 == -1)
            {
                //while neither button exists wait and check again
                await Task.Delay(200);
                strResult = await wv2Dig.CoreWebView2.ExecuteScriptAsync("document.documentElement.innerHTML;");
                strResult = Regex.Unescape(strResult);
                strResult = strResult.Remove(0, 1);
                strResult = strResult.Remove(strResult.Length - 1, 1);
                loc = strResult.IndexOf("btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button");
                loc2 = strResult.IndexOf("btn btn-disabled btn-lg btn-block add-to-cart-button");

            }
            //the button we want has been found 
            if (loc != -1)
            {
                iDig += 1;
                string mSubj = "Found";
                try
                {
                    sendSMS(mSubj, strDigURL);
                }
                catch
                {
                    label3.Text = "Email Error";
                }
                var functionString = string.Format(@"document.getElementsByClassName('btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button')[0].click();");
                await wv2Dig.CoreWebView2.ExecuteScriptAsync(functionString);
                
            }
            else //button we don't want found
            {
                if (bRun) //app is in run state, it can be paused
                    wv2Dig.CoreWebView2.Reload(); //Reload the page and check again
            }
        }
似乎在重新加载时,会出现错误页面

通过卸下WebView2预版本0.9.682并安装预版本0.9.579解决了以下问题

我有一个随机出现的新问题。应用程序冻结在
等待wv2Dig.ensureCrewWebView2Async()在从
表单加载调用的函数中


在执行
wv2Dig.CoreWebView2.Reload()
之前,我添加了
wv2Dig.CoreWebView2.Stop()
,此后我就没有看到问题。我认为这可能解决了问题。我说我认为是因为程序运行了很长一段时间没有出现问题,然后开始出现问题


在此过程中,我还降低了WebView2的预发布版本,因为WebView2不知何故完全停止工作。

您使用的是
NET Framework 4.6.2
还是更高版本?.NET Framework 4.7.2我认为您创建了一个无休止的循环。
ContentLoading
在加载内容之前被触发。。显示
ContentLoding
的代码,以便我们可以尝试提供帮助。添加了调用的代码和新问题。我们的想法是在页面完成加载之前检查页面的具体内容。我认为
loc
总是
-1
-然后它会一直重新加载,从而创建一个无休止的循环(有时会失败)。尝试单步执行代码。您应该改用
querySelector