在window service中调用mshtml,执行的过程总会出现Object reference not set to an instance of an object的错误
而相同的代码改成winform程序执行却一切正常.
代码如下,在ee.MoveNext()执行过程中会报这样的错,出现时间不一定.请问大家有碰见过见过这样的问题吗
IHTMLTable table = (IHTMLTable)tables.item(1, 1);
if (table.rows.length > 1)
{
try
{
System.Collections.IEnumerator ee = table.rows.GetEnumerator();
while (ee.MoveNext() && ee.Current != null)
{
HTMLTableRow row = (HTMLTableRow)ee.Current;
IHTMLElementCollection cells = row.cells;
System.Collections.IEnumerator ee2 = cells.GetEnumerator();
while (ee2.MoveNext() && ee2.Current != null)
{
IHTMLTableCell aCell = (IHTMLTableCell)ee2.Current;
IHTMLElement el = (IHTMLElement)aCell;
}
}
}
}
而相同的代码改成winform程序执行却一切正常.
代码如下,在ee.MoveNext()执行过程中会报这样的错,出现时间不一定.请问大家有碰见过见过这样的问题吗
IHTMLTable table = (IHTMLTable)tables.item(1, 1);
if (table.rows.length > 1)
{
try
{
System.Collections.IEnumerator ee = table.rows.GetEnumerator();
while (ee.MoveNext() && ee.Current != null)
{
HTMLTableRow row = (HTMLTableRow)ee.Current;
IHTMLElementCollection cells = row.cells;
System.Collections.IEnumerator ee2 = cells.GetEnumerator();
while (ee2.MoveNext() && ee2.Current != null)
{
IHTMLTableCell aCell = (IHTMLTableCell)ee2.Current;
IHTMLElement el = (IHTMLElement)aCell;
}
}
}
}
但是我在本机调试的时候服务也没有出错,只有在服务器上运行才出错,不知是哪里问题.
IHTMLTable table = (IHTMLTable)tables.item(1, 1);
if (table.rows.length > 1)
{
try
{
System.Collections.IEnumerator ee = table.rows.GetEnumerator();
while (ee.MoveNext() && ee.Current != null)
{
string strLine = "";
HTMLTableRow row = (HTMLTableRow)ee.Current;
IHTMLElementCollection cells = row.cells;
System.Collections.IEnumerator ee2 = cells.GetEnumerator();
while (ee2.MoveNext() && ee2.Current != null)
{
IHTMLTableCell aCell = (IHTMLTableCell)ee2.Current;
IHTMLElement el = (IHTMLElement)aCell;
strLine += el.innerText.Trim()
}
}
}
}