我正在制作一个带有一些textboxes
和一些labels
带有 abutton
和 a的小程序webbrowser
。代码不超过 80 行,它只包含一个按钮单击事件,该事件提供webbrowser
在文本框中输入的链接并neviage()
调用函数,第二个事件是浏览器的文档完成事件。错误如下
我已经在 stackoverflow 上搜索并搜索了很多关于访问冲突的信息,但我找不到任何适合我的目的的东西。异常不会在任何特定点发生。它随机出现并且总是在Application.Run
没有任何堆栈跟踪的情况下出现!
最困扰我的一件事是错误发生在 try 块中并且没有被捕获!
这个例外有什么解决办法吗?我尝试去调试->异常->公共语言运行时异常->系统并检查抛出,但它没有用。
我是新手程序员,所以请原谅我的经验不足!
编辑:代码
public Form1()
{
InitializeComponent();
}
private void simpleButton_Go_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textEdit_url.Text);
webBrowser1.ScriptErrorsSuppressed = true;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.Url.ToString().Contains("member/login"))
{
if (webBrowser1.Document.GetElementById("email_address")!=null)
{
webBrowser1.Document.GetElementById("email_address").SetAttribute("value", textEdit_username.Text);
webBrowser1.Document.GetElementById("member_password").SetAttribute("value", textEdit_password.Text);
var c = webBrowser1.Document.GetElementsByTagName("button");
foreach (HtmlElement element in c)
{
if (element.InnerText == "Login")
element.InvokeMember("click");
}
}
}
if (webBrowser1.Document.GetElementById("toolbar_login") != null && webBrowser1.Document.GetElementById("toolbar_login").InnerText == "Log In")
{
webBrowser1.Navigate("www.somesite.com");
}
else if (webBrowser1.Url.ToString() == textEdit_url.Text)
{
var c = webBrowser1.Document.GetElementsByTagName("button");
foreach (HtmlElement element in c)
{
if (element.InnerText == "Add to this list")
{
element.InvokeMember("click");
var te = webBrowser1.Document.GetElementsByTagName("textarea");
}
}
}
else
webBrowser1.Navigate(textEdit_url.Text);
}
编辑:更新
正如我建议的那样,我删除了 devexpress,创建了一个新的 winform 项目,将代码复制到该项目中,但错误仍然出现。新项目的堆栈跟踪是
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at app.Program.Main() in C:\Documents and Settings\admin\My Documents\Visual Studio 2010\Projects\app\app\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()