private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while (true)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
else
{
string content = downloadContent();
GetProfileNames(content);
GetTextFromProfile(content);
for (int i = 0; i < names.Count; i++)
{
namesAndTexts.Add(names[i] + " " + texts[i]);
}
if (InvokeRequired)
{
for (int f = 0; f < namesAndTexts.Count -1; f++)
{
BeginInvoke(new Action(() => textBox1.AppendText(namesAndTexts[f])), null);
}
}
reader.Close();
response.Close();
Thread.Sleep(1000);
}
}
}
I tried this part:
if (InvokeRequired)
{
for (int f = 0; f < namesAndTexts.Count -1; f++)
{
BeginInvoke(new Action(() => textBox1.AppendText(namesAndTexts[f])), null);
}
}
But its not working good its keeping adding the list over and over to the textBox. I want in the textbox to see it as:
daniel hello
yaron bye
danny good
And only once.
Another thing is if in the For im not doing namesAndTexts.Count - 1
but namesAndTexts.Count
then its throwing me error exception the namesAndTexts[f] that the index should not be less then zero but less then the list....
After this will work I need to check if the List is changed and make somehow automatic push up in the textBox lets say to fill the textBox to its size with lines and when its getting to the bottom start scroll up and keep update the new lines only from the bottom abnd push the old ones up from the top.
How can i do it?