. NET development of the site, if not using precompiled publishing, the site will be in the IIS6 application pool after the first visit is slow, in order to solve this problem, today wrote an automatic browsing tool, now share to everyone, the interface is as follows.
Key parts Source
//Manual Click to browse Private voidBtnbrowsing_click (Objectsender, EventArgs e) { if(btnbrowsing.enabled = =true&& chkenableautomaticbrowsing.checked = =true) {btnbrowsing.enabled=false; Thread Thread=NewThread (NewThreadStart (autobrowsing)); Thread. IsBackground=true; Thread. Start (); } Else{MessageBox.Show ("The task is executing!"); }} DateTime Temptime= Datetime.minvalue;//prevent multiple refreshes in a minute Private voidTimer1_Tick (Objectsender, EventArgs e) {DateTime dt=DateTime.Now; //clear a day log when the clock is turned if(dt. tolongtimestring () = ="0:00:00") {Rtxtlogs.text=string. Empty; } TimeSpan TS= DT-Temptime; //cannot be refreshed two times in 1 minutes if(TS. Totalminutes >0) { //Point Auto Refresh if(lstTime.Items.Contains (dt. Toshorttimestring ())) {Temptime= dt. AddMinutes (1); Btnbrowsing_click (NULL,NULL); } } } Private voidautobrowsing () {intItemtotalcount =0; Crossthreadcalls.safeinvoke ( This. Lvwebsitinfo,NewCrossthreadcalls.taskdelegate (Delegate() {Itemtotalcount=LvWebsitInfo.Items.Count; })); for(inti =0; i < Itemtotalcount; i++) { stringURL =string. Empty; Crossthreadcalls.safeinvoke ( This. Lvwebsitinfo,NewCrossthreadcalls.taskdelegate (Delegate() {URL= Lvwebsitinfo.items[i]. subitems[2]. Text; })); intRetry =0; RetryFlag:CrossThreadCalls.SafeInvoke ( This. WebBrowser1,NewCrossthreadcalls.taskdelegate (Delegate() {webbrowser1.navigate (URL); })); if(Waitwebpageload ()) {Crossthreadcalls.safeinvoke ( This. Rtxtlogs,NewCrossthreadcalls.taskdelegate (Delegate() {rtxtlogs.appendtext (URL+"Browse Success, browse time:"+ DateTime.Now.ToLongTimeString () +"\r\n\r\n"); Rtxtlogs.scrolltocaret (); })); Crossthreadcalls.safeinvoke ( This. Lvwebsitinfo,NewCrossthreadcalls.taskdelegate (Delegate() {lvwebsitinfo.items[i]. subitems[3]. Text =DateTime.Now.ToString (); })); } Else{Crossthreadcalls.safeinvoke ( This. Rtxtlogs,NewCrossthreadcalls.taskdelegate (Delegate() {rtxtlogs.appendtext (URL+"Browse failed and will retry"+ (retry +1) +"times \ r \ n"); Rtxtlogs.scrolltocaret (); })); if(Retry <2)//Retry 3 times{Retry++; Thread.Sleep ( the); GotoRetryflag; } crossthreadcalls.safeinvoke ( This. Rtxtlogs,NewCrossthreadcalls.taskdelegate (Delegate() {rtxtlogs.appendtext (URL+"Browse failed \r\n\r\n"); Rtxtlogs.scrolltocaret (); })); Crossthreadcalls.safeinvoke ( This. Lvwebsitinfo,NewCrossthreadcalls.taskdelegate (Delegate() {lvwebsitinfo.items[i]. subitems[3]. Text ="Auto Browse failed"; })); }} crossthreadcalls.safeinvoke ( This. btnbrowsing,NewCrossthreadcalls.taskdelegate (Delegate() {btnbrowsing.enabled=true; })); Crossthreadcalls.safeinvoke ( This. WebBrowser1,NewCrossthreadcalls.taskdelegate (Delegate() {webbrowser1.navigate ("About:blank"); })); } /// <summary> ///Determine If WebBrowser is loading a Web page, and can determine the page that includes the IFRAME/// </summary> /// <returns></returns> Private BOOLwaitwebpageload () {inti =0; stringsURL =string. Empty; while(true) {Delay ( -);//The system is delayed by 50 milliseconds, so little enough! Webbrowserreadystate webbrowserstate =webbrowserreadystate.uninitialized; Crossthreadcalls.safeinvoke ( This. WebBrowser1,NewCrossthreadcalls.taskdelegate (Delegate() {webbrowserstate=webbrowser1.readystate; })); if(webbrowserstate = = Webbrowserreadystate.complete)//first determine if the completion event occurs. { BOOLIsBusy =true; Crossthreadcalls.safeinvoke ( This. WebBrowser1,NewCrossthreadcalls.taskdelegate (Delegate() {isBusy=Webbrowser1.isbusy; })); if(!isbusy)//then judge whether the browser is busy{i= i +1; if(i = =2) {Crossthreadcalls.safeinvoke ( This. WebBrowser1,NewCrossthreadcalls.taskdelegate (Delegate() {sURL=webBrowser1.Url.ToString (); })); if(Surl.contains ("Res") || Surl.contains ("daohang.114so.cn"))//This is the case that no network is judged { return false; } Else { return true; } } Continue; } I=0; } } } Private voidDelay (intMillisecond)//delay the system time, but the system can perform other tasks at the same time;{DateTime current=DateTime.Now; while(Current. Addmilliseconds (millisecond) >DateTime.Now) {application.doevents ();//transfer of control rights } return; }
Click to download C # source code