这应该是.NET的BUG。
试试看下面的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private bool fixbug = false; public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://t.sohu.com");
} protected override void WndProc(ref Message m)
{
if ((m.Msg != 0x2a1 && m.Msg != 0x2a3) || !fixbug)
base.WndProc(ref m);
} private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
fixbug = false;
} private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
fixbug = true;
} }
}在我这里可以修复这个bug。原理是在装载网页的时候忽略掉两个可能导致出错的消息。
试试看下面的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private bool fixbug = false; public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://t.sohu.com");
} protected override void WndProc(ref Message m)
{
if ((m.Msg != 0x2a1 && m.Msg != 0x2a3) || !fixbug)
base.WndProc(ref m);
} private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
fixbug = false;
} private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
fixbug = true;
} }
}在我这里可以修复这个bug。原理是在装载网页的时候忽略掉两个可能导致出错的消息。
webBrowser1.ScriptErrorsSuppressed = true;
protected override void WndProc(ref Message m)
{
Program.Msg = m;
}
在Program中添加如下代码:
public static Message Msg;
然后运行你的程序。
出错的时候,将光标放在Msg上,看Msg是什么。
记录下来,然后按照我的程序修改。直到没有错误。
{
dynamic Iwb2; protected override void AttachInterfaces(object nativeActiveXObject)
{
Iwb2 = nativeActiveXObject;
Iwb2.Silent = true;
base.AttachInterfaces(nativeActiveXObject);
} protected override void DetachInterfaces()
{
Iwb2 = null;
base.DetachInterfaces();
}
}