我在VB.net应用程序中使用CefSharp作为浏览器,并希望从浏览器中检索返回值。
我只能在C#中找到解决方案,但我不能在VisualBasic中使其工作。
在这段代码中,我得到了以下错误:“error: Result不是Task的成员”
Dim script = "var returnValue = function(){ var value; value=10-2; return value; }"
Dim task As Threading.Tasks.Task = browser.EvaluateScriptAsync(script)
Dim taskResult As String
task.ContinueWith(Sub(t)
If t.IsFaulted = False Then
Dim response = t.Result 'Error: Result is not a member of Task'
If response.Success And response.Result IsNot Nothing Then
taskResult = response.Result
End If
End If
End Sub)
MsgBox(taskResult)这是我在CefSharp文档中找到的C#版本,但我无法将其转换为VB.net:
browser.EvaluateScriptAsync(script).ContinueWith(x =>
{
var response = x.Result;
if (response.Success && response.Result != null)
{
var onePlusOne = (int)response.Result;
//Do something here (To interact with the UI you must call BeginInvoke)
}
});发布于 2019-08-04 19:41:55
我更改了你的Javascript,让它返回值。根据注释中的建议,我更改了task的声明以更正您提到的错误。
Dim script = "(function(){ var value; value=10-2; return value; })();"
Dim task As Task(Of JavascriptResponse) = browser.EvaluateScriptAsync(script)
Dim taskResult As String
task.ContinueWith(
Sub(t)
If t.IsFaulted = False Then
Dim response = t.Result 'Error: Result is not a member of Task'
If response.Success And response.Result IsNot Nothing Then
taskResult = response.Result
End If
End If
End Sub)
MsgBox(task.Result.Result)发布于 2021-04-09 08:27:12
Dim html As String = ""
Using t As Task(Of String) = WebView21.ExecuteScriptAsync("document.documentElement.outerHTML;")
Do Until t.IsCompleted
Application.DoEvents()
Loop
html = t.Result
End Using
html = Regex.Unescape(html)
html = html.Remove(0, 1)
html = html.Remove(html.Length - 1, 1)
html = html.Replace("<!--!-->", "")https://stackoverflow.com/questions/57340221
复制相似问题