c# - My button needs two clicks instead of one -



c# - My button needs two clicks instead of one -

i working on little app in c# refreshes web page until conditions met. have "fire" = start refreshing button , "stop!" button supposed stop operation. problem takes 2 tries click stop button instead of 1. below code:

updated code timer. still think there can improve utilize of timer, think doesn't update every sec after first 2-3 refreshes or doesn't refresh @ all. there flaw in code can't detect?

private void firebuttonclick(object sender, eventargs e) { seek { if (webbrowser1.url.tostring().startswith("some url")) { _stopped = false; _timer.tick += new eventhandler(refreshbrowser); _timer.interval = (1000) * (1); _timer.enabled = true; _timer.start(); } else { messagebox.show("you must logon first."); return; } } grab (exception ex) { messagebox.show(ex.message); } } private void refreshbrowser(object sender, eventargs e) { string content = "disabled"; string baseurl = @"http://some url"; string newurl = string.empty; string buttonxpath = @"/html/body/div/div[6]/table/tr/td[2]/table/tr/td/table/tr/td/table/tr[3]/td[2]/div[4]/a"; webbrowser1.refresh(); _proceed = false; if (!content.tolower().equals("disabled") && !_stopped) { if (!_stopped) { htmlagilitypack.htmldocument htmldocument = new htmlagilitypack.htmldocument(); htmldocument.loadhtml(webbrowser1.documenttext); htmlnode node = htmldocument.documentnode.selectsinglenode(buttonxpath); content = node.getattributevalue("disabled", string.empty); newurl = node.getattributevalue("href", string.empty); } } else { webbrowser1.navigate(baseurl + newurl); } } private void webbrowser1_navigated(object sender, webbrowsernavigatedeventargs e) { _proceed = true; urltextbox.text = webbrowser1.url.tostring(); } private void mainpagebuttonclick(object sender, eventargs e) { seek { webbrowser1.navigate(_mainpage); } grab (exception ex) { messagebox.show(ex.message); } } private void gobuttonclick(object sender, eventargs e) { seek { webbrowser1.navigate(urltextbox.text); } grab (exception ex) { messagebox.show(ex.message); } } private void stopbuttonclick(object sender, eventargs e) { _timer.stop(); _proceed = true; _stopped = true; }

}

you should modify code utilize timer. when misuse gui thread , create periodic calls application.doevents(); click can handled @ place meaning have come in loop process event.

this absolute no go gui programming. utilize timer instead.

here illustration on how timer can used periodically phone call method. in case perform refresh of page.

c# button click

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -