How can i make that the variable t will be added ot textBox each time once when it should be when itsi nside the while loop ?


private void backgroundworker1_dowork(object sender, doworkeventargs e)           {              backgroundworker worker = sender backgroundworker;               list<string> tempnamesandtexts = new list<string>();              string tempdownload = downloadcontent();              getprofilenames(tempdownload);              gettextfromprofile(tempdownload);              (int = 0; < names.count; i++)              {                  tempnamesandtexts.add(names[i] + " " + texts[i]);                                }              if (invokerequired)              {                  begininvoke(new action(() => tempnamesandtexts.foreach(item => textbox1.appendtext(item + environment.newline))));              }              while (true)              {                  namesandtexts = new list<string>();                  if ((worker.cancellationpending == true))                  {                      e.cancel = true;                      break;                  }                  else                  {                            string content = downloadcontent();                      getprofilenames(content);                      gettextfromprofile(content);                      (int = 0; < names.count; i++)                      {                           namesandtexts.add(names[i] + " " + texts[i]);                      }                      if (invokerequired)                      {                          bool result = tempnamesandtexts.sequenceequal(namesandtexts);                          if (result == true)                          {                          }                          else                          {                              var t = namesandtexts.last();                                  if (textbox1.invokerequired)                              {                                                                        begininvoke(new action(() => textbox1.appendtext(t)), null);                                                                                                        }                          }                                                  }                      reader.close();                      response.close();                      thread.sleep(30000);                  }              }          }

im download content site every 30 seocnds when there change want add text in variable t once. want loop wile loop continue.

the problem in way keep adding , adding t variable non stop when if condition false , doing variable t wich line:

begininvoke(new action(() => textbox1.appendtext(t)), null);

i need when condition happen add t once , continue loop , if bool false add t variable again in case adding same text in t variable non stop.

i tried ot use break; , return; right after line while loop not continue.

how can ?


danieli

your problem appears once namesandtexts changes, never equal tempnamesandtexts again, sequenceequal return false. need update tempnamesandtexts each time changes.

                            if (textbox1.invokerequired)                             {                                                                      begininvoke(new action(() => textbox1.appendtext(t)), null);                                     tempnamesandtexts = namesandtexts;                             }

, way, recommend using timer rather putting thread sleep 30 seconds.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'