frameBase2.contentWindow出错的问题解决

在使用 “using mshtml;”的过程中出现了这个问题


类型于:


public static HTMLDocumentClass getCurrentInterlibHtmlPage()
        {
            HTMLDocumentClass htmlDoc = IeCurWin.getCurrentWindowPage();
            if (htmlDoc == null) return null;
            String pageUrl = ToolUtil.trimStringNull(htmlDoc.url);
            String titleStr = ToolUtil.trimStringNull(htmlDoc.title);
            //MessageBox.Show(titleStr);
            if (titleStr.StartsWith("流通管理 -- 3RD Auto System Interlib") && pageUrl.EndsWith("maxLoanMain.jsp"))
            {
                HTMLDocument htmlDocument = (HTMLDocument)htmlDoc;
                IHTMLElement iframeElement = htmlDocument.getElementById("mainFrame");
                /*MessageBox.Show("[------Test 1-------] " + iframeElement.outerHTML);


                IHTMLFrameBase2 frameBase2 = (IHTMLFrameBase2)iframeElement;
                if (frameBase2.readyState.Equals("complete", StringComparison.OrdinalIgnoreCase))
                {
                    //这一行一执行 frameBase2.contentWindow 就已经抛出异常,
                    //异常信息为:System.InvalidCastException : Specified cast is not valid.
                    MessageBox.Show("[------Test 2-------] " + (frameBase2.contentWindow == null ? "yes" : "no"));
                }*/
                //表示带帧的
                mshtml.IHTMLFrameBase2 iFrame = (mshtml.IHTMLFrameBase2)htmlDoc.all.item("mainFrame", 0);
                mshtml.IHTMLDocument2 iHTMLDocument2 = iFrame.contentWindow.document;
                htmlDoc = (HTMLDocumentClass)iHTMLDocument2;
            }
            return htmlDoc;
        }
百度查找是否有其他人员遇到相关问题,查找到
<a href="https://bbs.csdn.net/topics/390820111">https://bbs.csdn.net/topics/390820111</a>但是这个问题居然没解决,很绝望。

从新过一遍代码,看看是哪里的问题:发现我是在线程中调用的。

搞了半天后,终于找到了解决方法,加上invoke就可以解决问题了:

this.Invoke(new MethodInvoker(delegate
   {
                        
   }));

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值