c# - Why does WebClient freeze my program? -


i can try string url when program gui freezes

        private void button1_click(object sender, eventargs e)     {         try         {             if (listbox1.items.count > 10)             {                 messagebox.show("wow ! try hack iran ? :)");                 application.exit();             }              long fromnumber = convert.toint64(textbox1.text);             long = convert.toint64(textbox2.text);             int badn = 0;             int godn = 0;             int ern = 0;             string slas;             long gethow = ((to - fromnumber) + 1);               if (fromnumber < 9010000000 && > 9399999999 && fromnumber > to)             {                 messagebox.show("you entered wrong numbers !");             }             if (fromnumber >= 9010000000 && >= 9010000000)             {                 this.text = "myirancell bruteforce  [ status : attacking ]";                 (long = 1; < gethow; i++)                 {                     int ico = convert.toint32(i);                     int ico2 = convert.toint32(gethow + 1);                     if (ico == ico2)                     {                         startt.stop();                     }                     string irancell = "https://xxx.xxx/?id=";                     // todo: complete member initialization                     var request = irancell + (fromnumber - 1 + i);                     //                      var client = new webclient();                      client.downloadstringcompleted += new downloadstringcompletedeventhandler(downloadstringcompletedhandler);                      result=client.downloadstringasync(request);                    //var result = client.downloadstring(request);                     slas = "0" + convert.tostring((fromnumber - 1 + i));                     if (result == "2-p")                     {                         if (!listbox1.items.contains(slas))                         {                              listbox1.items.add(slas);                             godn++;                         }                      }                     if (result == "0")                     {                         badn++;                         label12.text = convert.tostring(badn);                       }                     if (result != "0" && result != "2-p")                     {                         ern++;                         label6.text = convert.tostring(ern);                       }                     label9.text = convert.tostring(listbox1.items.count);                      //  if (i == gethow)                     // {                     //  groupbox1.enabled = true;                     //   groupbox2.enabled = true;                     //   button4.enabled = true;                      //}                 }             }         } 

i read message on stackoverflow problem, there have use client.downloadstringasync await unknown command in program.i edit full code

if you're targetting .net before 4.5 there no async/await - instead can use async version of downloadstringasync raises event when string downloaded

var client = new webclient(); client.downloadstringcompleted += new downloadstringcompletedeventhandler(downloadstringcompletedhandler);  (long = 1; < gethow; i++) {     string webadress = "https://xxxxxx.xxx/web?id=";     var request = webadress + (fromnumber - 1 + i);          client.downloadstringasync(request);  }  // -- > elsewhere in form void downloadstringcompletedhandler(object sender, downloadstringcompletedeventargs e) {     slas = "0" + convert.tostring((fromnumber - 1 + i));     if (e.result == "test")     {         if (!listbox1.items.contains(slas))         {                              listbox1.items.add(slas);              godn++;          }     } } 

if of code must in button click, can inline event handler

var client = new webclient(); client.downloadstringcompleted += (s,e) => {     slas = "0" + convert.tostring((fromnumber - 1 + i));     if (e.result == "test")     {         if (!listbox1.items.contains(slas))         {                              listbox1.items.add(slas);              godn++;          }     } };  (long = 1; < gethow; i++) {     string webadress = "https://xxxxxx.xxx/web?id=";     var request = webadress + (fromnumber - 1 + i);          client.downloadstringasync(request);  } 

edit: have updated code in question answer youve assumed downloadstringasync returns result - doesn't. method returns nothing. string returned in event handler

var client = new webclient(); client.downloadstringcompleted += new downloadstringcompletedeventhandler(downloadstringcompletedhandler); result=client.downloadstringasync(request); // <-- line wrong 

it should be

client.downloadstringasync(request); 

and receive string inside downloadstringcompletedhandler e.result


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -