溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

openwebkitsharp出現(xiàn)COM對(duì)象與其基礎(chǔ)RCW分開(kāi)后就不能再使用的示例分析

發(fā)布時(shí)間:2021-09-18 14:18:58 來(lái)源:億速云 閱讀:178 作者:柒染 欄目:編程語(yǔ)言

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)openwebkitsharp出現(xiàn)COM對(duì)象與其基礎(chǔ)RCW分開(kāi)后就不能再使用的示例分析,文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

Open-Webkit-Sharp實(shí)驗(yàn):

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);//最好不要在這個(gè)事件中show,否則容易混亂出錯(cuò)
            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");
        }

先點(diǎn)button1(以便啟用script),再點(diǎn)button3,然后關(guān)閉程序主窗體,就出現(xiàn):COM 對(duì)象與其基礎(chǔ) RCW 分開(kāi)后就不能再使用

網(wǎng)上有相應(yīng)分析,其實(shí)說(shuō)白了,就是C#中沒(méi)有相應(yīng)處理COM中相關(guān)資源,想來(lái)想去,我添加將事件去掉代碼:

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            webKitBrowser.ShowJavaScriptAlertPanel -= webKitBrowser_ShowJavaScriptAlertPanel;
            webKitBrowser.DocumentCompleted -= webKitBrowser_DocumentCompleted;
        }

然后一切都OK了。

上述就是小編為大家分享的openwebkitsharp出現(xiàn)COM對(duì)象與其基礎(chǔ)RCW分開(kāi)后就不能再使用的示例分析了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI