2 lrl1986 lrl1986 于 2014.07.29 21:29 提问

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);
                }
            }
        }

2个回答

adailee
adailee   2014.09.05 10:43

第一:确定DocumentCompleted事件只被绑定了一次吗?
第二:确定这个页面只是加载了一次吗?

feiyun0112
feiyun0112   Rxr 2014.11.17 17:53

判断e.Url是不是当前访问的网址

Csdn user default icon
上传中...
上传图片
插入图片