这期内容当中小编将会给大家带来有关openwebkitsharp出现COM对象与其基础RCW分开后就不能再使用的示例分析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
private void button1_Click(object sender, EventArgs e)
{
webKitBrowser.UseJavaScript = true;
webKitBrowser.Navigate("http://localhost/index.html");
webKitBrowser.ShowJavaScriptAlertPanel += webKitBrowser_ShowJavaScriptAlertPanel;
webKitBrowser.DocumentCompleted += webKitBrowser_DocumentCompleted;
}
void webKitBrowser_ShowJavaScriptAlertPanel(object sender, WebKit.ShowJavaScriptAlertPanelEventArgs e)
{
//MessageBox.Show("msg:" + e.Message);//最好不要在这个事件中show,否则容易混乱出错
MessageBox.Show(e.Message);
Console.WriteLine(sender.ToString() + ":"+e.Message);
}
private void webKitBrowser_Load(object sender, EventArgs e)
{
webKitBrowser.GetScriptManager.ScriptObject = this;
}
private void button2_Click(object sender, EventArgs e)
{
//string strScript = "messageBox(document.getElementById(\"testelement\").innerText = \"123456\")";
//webKitBrowser.StringByEvaluatingJavaScriptFromString(strScript);
WebKit.JSCore.JSValue V = webKitBrowser.GetScriptManager.CallFunction("test", new object[] { "zs", "addrr" });
//Console.WriteLine("jsvalue=" + V.ToString());
this.Text = webKitBrowser.DocumentTitle;
}
private void button3_Click(object sender, EventArgs e)
{
webKitBrowser.Navigate("http://www.taobao.com");//("http://www.pudn.com/Download/item/id/4061758.html"); //("https://www.baidu.com");
}
先点button1(以便启用script),再点button3,然后关闭程序主窗体,就出现:COM 对象与其基础 RCW 分开后就不能再使用
网上有相应分析,其实说白了,就是C#中没有相应处理COM中相关资源,想来想去,我添加将事件去掉代码:
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
webKitBrowser.ShowJavaScriptAlertPanel -= webKitBrowser_ShowJavaScriptAlertPanel;
webKitBrowser.DocumentCompleted -= webKitBrowser_DocumentCompleted;
}
然后一切都OK了。
上述就是小编为大家分享的openwebkitsharp出现COM对象与其基础RCW分开后就不能再使用的示例分析了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/2963604/blog/5010576