Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Openwebkitsharp shows that the COM object can no longer be used after it is separated from its underlying RCW.

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you an example analysis that can no longer be used after the openwebkitsharp appears that the COM object is separated from its basic RCW. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Open-Webkit-Sharp experiment: 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); / / it is best not to show in this event, otherwise it is prone to confusion and error 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");})

Click button1 (to enable script), click button3, and then close the main form of the program, which appears: the COM object can no longer be used after it is separated from its underlying RCW

There is a corresponding analysis on the Internet, in fact, to put it bluntly, there is no corresponding processing of relevant resources in COM in C#. After thinking about it, I added the code to remove the event:

Private void Form1_FormClosed (object sender, FormClosedEventArgs e)

{

WebKitBrowser.ShowJavaScriptAlertPanel-= webKitBrowser_ShowJavaScriptAlertPanel

WebKitBrowser.DocumentCompleted-= webKitBrowser_DocumentCompleted

}

And then everything OK.

The above is the example analysis that can no longer be used after the COM object is separated from its basic RCW in openwebkitsharp shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report