vb.net - Faster HTTPWEBREQUEST/WEBRESPONSE - Too Slow -
is there way speed up? going through list of 2000 , going 1 one. please note, have tried "service manager max connections/default connections etc. none of these have been valuable solutions.
' ' created sharpdevelop. ' user: merickson2 ' date: 3/22/2014 ' time: 5:59 pm ' ' change template use tools | options | coding | edit standard headers. ' imports system.net imports system.io imports system.text imports system.text.regularexpressions public partial class mainform dim fetch1 integer dim newlist1 integer dim splitlist() string dim tempcookies new cookiecontainer dim encoding new utf8encoding public sub new() ' me.initializecomponent call required windows forms designer support. me.initializecomponent() ' ' todo : add constructor code after initializecomponents ' end sub sub mainformload(sender object, e eventargs) 'do stuff end sub sub button1click(sender object, e eventargs) dim postdata string = "login data" dim bytedata byte() = encoding.getbytes(postdata) dim postreq httpwebrequest = directcast(webrequest.create("http://login"), httpwebrequest) postreq.method = "post" postreq.keepalive = true postreq.cookiecontainer = tempcookies postreq.contenttype = "application/x-www-form-urlencoded" postreq.referer = "http://login postreq.useragent = "mozilla/5.0 (windows; u; windows nt 6.1; ru; rv:1.9.2.3) gecko/20100401 firefox/4.0 (.net clr 3.5.30729)" postreq.contentlength = bytedata.length dim postreqstream stream = postreq.getrequeststream() postreqstream.write(bytedata, 0, bytedata.length) postreqstream.close dim postresponse httpwebresponse postresponse = directcast(postreq.getresponse(), httpwebresponse) tempcookies.add(postresponse.cookies) dim postreqreader new streamreader(postresponse.getresponsestream()) dim thepage string = postreqreader.readtoend initleech() end sub public sub initleech() x = 0 listbox2.items.count - 1 splitlist = split(listbox2.items(x), "|") dim postdata2 string = "search data" dim bytedata2 byte() = encoding.getbytes(postdata2) dim postreq2 httpwebrequest = directcast(webrequest.create("http://search"), httpwebrequest) postreq2.method = "post" postreq2.keepalive = false postreq2.cookiecontainer = tempcookies postreq2.contenttype = "application/x-www-form-urlencoded" postreq2.referer = "http://search" postreq2.useragent = "mozilla/5.0 (windows; u; windows nt 6.1; ru; rv:1.9.2.3) gecko/20100401 firefox/4.0 (.net clr 3.5.30729)" postreq2.contentlength = bytedata2.length dim postreqstream2 stream = postreq2.getrequeststream() postreqstream2.write(bytedata2, 0, bytedata2.length) postreqstream2.close dim postresponse2 httpwebresponse postresponse2 = directcast(postreq2.getresponse(), httpwebresponse) dim postreqreader2 new streamreader(postresponse2.getresponsestream()) dim thepage2 string = postreqreader2.readtoend dim splitit() string dim checkrating string dim wrongstuff string if len(thepage2) > 10 if instr(thepage2,"ucdmc:") > 0 splitit = split(thepage2,"ucdmc:",7) checkrating = splitit(1).substring(29,2) checkrating = replace(checkrating,".", "") textbox1.text = checkrating dim fullname string dim truename string dim dob string dim sex string dim startp integer dim endp integer dim addy string startp = instr(thepage2,"ucdmc:") + 129 startp = instr(startp, thepage2, ">") endp = instr(startp, thepage2, "</") fullname = trim(strings.mid(thepage2, startp, endp - startp)) fullname = replace(fullname, ">", "") fullname = replace(fullname, " ", " ") truename = splitlist(0) + ", " + splitlist(1) + " " + splitlist(2) truename = regex.replace(truename, "\p{c}+", "") fullname = regex.replace(fullname, "\p{c}+", "") wrongstuff = "" if trim(fullname) = trim(truename) 'do nothing else wrongstuff = " + (wrong: name" end if startp = endp + 23 endp = instr(startp, thepage2, "</") dob = trim(strings.mid(thepage2, startp, endp - startp)) dob = replace(dob, "<", "") dim dobcheck string dobcheck = replace(dob, "-", "") if dobcheck = splitlist(3) 'do nothing else if wrongstuff = "" wrongstuff = " + (wrong: dob" else wrongstuff = wrongstuff + "/dob" end if end if startp = endp + 23 endp = instr(startp, thepage2, "-") sex = trim(strings.mid(thepage2, startp, endp - startp)) sex = replace(sex, "<", "") if sex = splitlist(4) 'do nothing else if wrongstuff = "" wrongstuff = " + (wrong: sex" else wrongstuff = wrongstuff + "/sex" end if end if startp = endp + 62 endp = instr(startp, thepage2, ",") addy = trim(strings.mid(thepage2, startp, endp - startp)) addy = replace(addy, "<br>", " - ") addy = replace(addy, chr(34), "") addy = replace(addy, ">", "") if instr(addy, "/td") > 0 addy = "no address given" end if if wrongstuff = "" 'do nothing else wrongstuff = wrongstuff + ")" end if if checkbox1.checked = true wrongstuff = wrongstuff + " + {" + listbox2.items(x).tostring + "}" end if if checkrating > 6 if splitlist(2) = "" listbox1.items.add("[" + splitlist(0) + ", " + splitlist(1) + " * " + splitlist(3) + " * " + splitlist(4) + "] + (weight: " + checkrating + ")" + " + (mrn: " + splitit(1).substring(0,7) + ") + [" + fullname + " * " + dobcheck + " * " + sex + "] + {" + addy + "}" + wrongstuff) else listbox1.items.add("[" + splitlist(0) + ", " + splitlist(1) + " " + splitlist(2) + " * " + splitlist(3) + " * " + splitlist(4) + "] + (weight: " + checkrating + ")" + " + (mrn: " + splitit(1).substring(0,7) + ") + [" + fullname + " * " + dobcheck + " * " + sex + "] + {" + addy + "}" + wrongstuff) end if label2.text = "existing patients: " + listbox1.items.count.tostring else if splitlist(2) = "" listbox3.items.add("[" + splitlist(0) + ", " + splitlist(1) + " * " + splitlist(3) + " * " + splitlist(4) + "] + (weight: " + checkrating + ")" + " + (mrn: " + splitit(1).substring(0,7) + ") + [" + fullname + " * " + dobcheck + " * " + sex + "] + {" + addy + "}" + wrongstuff) else listbox3.items.add("[" + splitlist(0) + ", " + splitlist(1) + " " + splitlist(2) + " * " + splitlist(3) + " * " + splitlist(4) + "] + (weight: " + checkrating + ")" + " + (mrn: " + splitit(1).substring(0,7) + ") + [" + fullname + " * " + dobcheck + " * " + sex + "] + {" + addy + "}" + wrongstuff) end if label3.text = "new patients: " + listbox3.items.count.tostring end if else if checkbox1.checked = true wrongstuff = " + {" + listbox2.items(x).tostring + "}" end if listbox3.items.add(splitlist(0) + ", " + splitlist(1) + " + (not found)" + wrongstuff) label3.text = "new patients: " + listbox3.items.count.tostring end if end if label1.text = "checking " & listbox1.items.count + listbox3.items.count & " of " & listbox2.items.count.tostring fetch1 = fetch1 + 1 application.doevents() next if fetch1.tostring = test1.text if listbox1.items.count + listbox3.items.count = listbox2.items.count label1.text = "mission complete" label1.forecolor = color.green else label1.text = "checking " & listbox1.items.count + listbox3.items.count & " of " & listbox2.items.count.tostring end if else fetch1 = fetch1 + 1 end if end sub sub button2click(sender object, e eventargs) dim tempname string dim temppath string dim pcount integer pcount = listbox2.items.count using dialog new openfiledialog dialog.filter = "text files (*.txt)|*.txt|all files (*.*)|*.*" if dialog.showdialog() <> dialogresult.ok return dim string = my.computer.filesystem.readalltext(dialog.filename) listbox2.items.addrange(io.file.readalltext(dialog.filename).split(new string() {environment.newline}, stringsplitoptions.removeemptyentries)) tempname = system.io.path.getfilenamewithoutextension(dialog.filename) + ".txt" temppath = dialog.filename end using listbox2.selectedindex = 0 pcount = listbox2.items.count - pcount richtextbox1.text = richtextbox1.text + tempname + ": " + pcount.tostring + vbcrlf test0.text = listbox2.items.count.tostring newlist1 = newlist1 + 1 label5.text = "patient files loaded : " + newlist1.tostring end if end sub end class
Comments
Post a Comment