Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

c# - CefSharp use DevToolsClient execute Method after, call Wait() function Waiting, Lead to program card to death?

CefSharp Version: 86.0.241.0
.Net Framework 4.5.2
I am new to C# and my English is not good. Sorry.... Try a variety of methods to implement:

private void button18_Click(object sender, EventArgs e)
{
    //1
    DevToolsClient devTool = chromiumWebBrowser1.GetBrowser().GetDevToolsClient();
    devTool.ExecuteDevToolsMethodAsync("Browser.getVersion").Wait();// stuck
    
    //2
    DevToolsClient dev = DevToolsExtensions.GetDevToolsClient(chromiumWebBrowser1);
    dev.ExecuteDevToolsMethodAsync("Browser.getVersion").Wait();// stuck
    
}
// load complete after:
chromiumWebBrowser1.FrameLoadEnd += new EventHandler<FrameLoadEndEventArgs>(new Action<object, FrameLoadEndEventArgs>((s, ea) => {
    IBrowser browser = chromiumWebBrowser1.GetBrowser();
    DevToolsClient devTool = chromiumWebBrowser1.GetBrowser().GetDevToolsClient();
    //devTool.Browser.GetVersionAsync().Wait();      //execute nomal
    devTool.DOM.GetDocumentAsync().Wait();  // stuck
}));
//
private void button1_Click(object sender, EventArgs e)
{
    DevToolsClient devTool = chromiumWebBrowser1.GetBrowser().GetDevToolsClient();
    //devTool.Page.ReloadAsync();  //nomal  page reload
    devTool.Page.ReloadAsync().Wait(); // stuck
}

In addition to being successful Browser.GetVersionAsync() in FrameLoadEnd event .

question from:https://stackoverflow.com/questions/65895251/cefsharp-use-devtoolsclient-execute-method-after-call-wait-function-waiting

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A solution has been found! use async/await solve.

private async void button1_Click(object sender, EventArgs e)
{
    DevToolsClient devTool = chromiumWebBrowser1.GetBrowser().GetDevToolsClient();
    DevToolsMethodResponse resp = await devTool.ExecuteDevToolsMethodAsync("DOM.getDocument");
    Console.WriteLine(resp.ResponseAsJsonString);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...