问题描述
- C# 这段代码总是自动执行两次
-
private void Web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser web = sender as WebBrowser; web.Document.Window.Error += new HtmlElementErrorEventHandler(Web_Error);//去掉错误提示 if (web.Tag != null && web.Tag.GetType() == typeof(DataRowView)) { DataRowView drv = web.Tag as DataRowView; if (web.Url.ToString().IndexOf("id=" + drv["CargoId"]) == -1) { SetDataRowViewText(drv, null, null, null, "准备浏览...", "准备" + Be.BeforeBrowse.ToString() + "秒"); Console.WriteLine("********准备浏览GGG********" + drv["CargoId"] + "********" + DateTime.Now); System.Windows.Forms.Timer timerBrowse = new System.Windows.Forms.Timer(); timerBrowse.Interval = Be.BeforeBrowse * 1000; timerBrowse.Tag = web; timerBrowse.Tick += new EventHandler(timerBrowse_Tick); timerBrowse.Start(); Console.WriteLine("********准备浏览EEE********" + drv["CargoId"] + "********" + DateTime.Now); } else { Console.WriteLine("********浏览后GGG********" + drv["CargoId"] + "********" + DateTime.Now); SetDataRowViewText(drv, null, null, null, "正在浏览...", "浏览" + Be.Browseing.ToString() + "秒"); System.Windows.Forms.Timer timerDispose = new System.Windows.Forms.Timer(); timerDispose.Interval = Be.Browseing * 1000; timerDispose.Tag = web; timerDispose.Tick += new EventHandler(timerDispose_Tick); timerDispose.Start(); Console.WriteLine("********浏览后EEE********" + drv["CargoId"] + "********" + DateTime.Now); } } }
解决方案
第一:确定DocumentCompleted事件只被绑定了一次吗?
第二:确定这个页面只是加载了一次吗?
解决方案二:
判断e.Url是不是当前访问的网址
时间: 2024-10-30 06:15:11