110,549
社区成员
发帖
与我相关
我的任务
分享
private void ListenIE()
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
mshtml.IHTMLDocument2 htmlDoc;
String filename = null;
String str = null;
try
{
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
//Console.WriteLine(ie.LocationURL);
htmlDoc = ie.Document as mshtml.IHTMLDocument2;
//System.Threading.Thread.Sleep(3000);
IntPtr activeHwnd = GetForegroundWindow();
//Console.WriteLine("activeHwnd====" + activeHwnd);
WriteLog("--------------");
if (htmlDoc != null)
{
if (ie.HWND == activeHwnd.ToInt32())
{
ie.Refresh();
}
try
{
str = htmlDoc.body.innerHTML;
//Console.WriteLine("=========>" + str);
if(str.Contains("HTTP 错误 404 - 文件或目录未找到"))
{
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(3000);
CloseIE();
WriteLog("HTTP 错误 404");
//CloseWindow(activeHwnd);
//errorInforToUrl();
}
if (str.Contains("HTTP Status 500 "))
{
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(3000);
CloseIE();
WriteLog("HTTP Status 500");
//CloseWindow(activeHwnd);
//errorInforToUrl();
}
if (str.Contains("找不到服务器或 DNS 错误"))
{
System.Threading.Thread.Sleep(3000);
CloseIE();
//CloseWindow(activeHwnd);
timeIE.Enabled = false;
timeIE.Stop();
WriteLog("找不到服务器或 DNS 错误");
//errorInforToUrl();
}
if (str == null) //白屏
{
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(3000);
CloseIE();
WriteLog("str == null");
//errorInforToUrl();
}
}
catch(Exception e) //白屏异常
{
//Console.WriteLine("e=============" + e.ToString());
WriteLog("异常=" + e.ToString());
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(5000);
CloseIE();
WriteLog("白屏异常");
//CloseWindow(activeHwnd);
//sendErrorInfor("termid=" + termid + "&errmsg=" + e.ToString());
//errorInforToUrl();
}
}
}
}
}
catch(Exception e)
{
WriteLog("异常="+e.ToString());
}
}