browser - C# Webclient not working properly -
i've created simple tool can find sign option in websites (200 website list in arraylist). using webbrowser has problem of cache , cookie switched webclient. works fine when put breakpoints , debug when run normally, include websites doesn't have signup option. here code
private void btnsearch_click(object sender, eventargs e) { timer1.enabled = true; timer1.start(); }
timer1 code
string st; private void timer1_tick(object sender, eventargs e) { st = ""; application.doevents(); try { st = lst[dataindex2].tostring(); using (webclient asyncwebrequest = new webclient()) { asyncwebrequest.downloaddatacompleted += asyncwebrequest_downloaddatacompleted; uri urltorequest = new uri(st); asyncwebrequest.downloaddataasync(urltorequest); asyncwebrequest.dispose(); } dataindex2++; if (dataindex2 == lst.count) { timer1.stop(); lblstatus.text = "stopped"; lblstatus.forecolor = color.darkred; messagebox.show("search completed"); } } catch (exception ex) { timer1.stop(); lblstatus.text = "stopped"; lblstatus.forecolor = color.darkred; timer1.dispose(); messagebox.show(ex.message); return; }
asyncwebrequest_downloaddatacompleted code:
private void asyncwebrequest_downloaddatacompleted(object sender, downloaddatacompletedeventargs e) { if (e.error != null) { timer1.stop(); ena(); lblstatus.text = "stopped"; lblstatus.forecolor = color.darkred; timer1.dispose(); messagebox.show(e.error.message); } if (e.result != null && e.result.length > 0) { string browsetext = ""; int = isuccess = 0; browsetext = encoding.default.getstring(e.result); isuccess = browsetext.indexof("sign up") + 1; if (isuccess == 0) { } else { listbox1.items.add(st); domaincount++; lbldomaincount.forecolor = color.darkgreen; lbldomaincount.text = domaincount.tostring(); } } else { } } } else { messagebox.show("no data found."); } }
please , if there alternate of webclient doesn't hang gui please suggest. ty.
you dispose webclient start download.
asyncwebrequest.downloaddataasync(urltorequest); asyncwebrequest.dispose();
please , if there alternate of webclient doesn't hang gui
see my other answer creates wrapper webclient able use async/await. httpclient can alternative too.
Comments
Post a Comment