高手进!!访问IHTMLAnchorElement的属性时,出错:尝试读取或修改受保护的内存
恶猫 2008-10-25 02:28:21 foreach (mshtml.IHTMLElement el in doc2.links)
{
IHTMLAnchorElement ia = (IHTMLAnchorElement)el as IHTMLAnchorElement;
string href = "";
if (ia != null)
{
href = ia.href;
flag = true;
}
//ia.href;// (string)((IHTMLAnchorElement)el).href;//el.getAttribute("href", 0).ToString();//
string txt = (string)el.innerText;
只贴一部分代码...................
这样处理的结果,如果在 ia!=null 这一行前加上try ...那程序运行的结果,就是,,平均运行2-3次.会出一次错,结果是空.
错就在 href=ia.href 这里...
ia 是转换完的 IHTMLAnchorElement 对象.
可是只要一访问属性,就会出错.(我是在线程里访问的)
奇怪的就是,有时出错,有时不出错.机会差不多是 40% vs 60% 这样的机率.
GG和百度,都搜遍了,没有碰到我这样的情况.