C# Thread issues
- by Mike
What I have going on is a listview being dynamically created from a previous button click. Then ti starts a background worker in which should clear out the listview and populate the iistview with new information every 30 seconds.
I continously get: Cross-thread operation not valid: Control 'listView2' accessed from a thread other than the thread it was created on.
private void watcherprocess1Updatelist()
{
listView2.Items.Clear();
string betaFilePath1 = @"C:\Alpha\watch1\watch1config.txt";
using (FileStream fs = new FileStream(betaFilePath1, FileMode.Open))
using (StreamReader rdr = new StreamReader((fs)))
{
while (!rdr.EndOfStream)
{
string[] betaFileLine = rdr.ReadLine().Split(',');
using (WebClient webClient = new WebClient())
{
string urlstatelevel = betaFileLine[0];
string html = webClient.DownloadString(urlstatelevel);
File.AppendAllText(@"C:\Alpha\watch1\specificconfig.txt", html);
}
}
}