private void showStatistics(string path)
{
Thread thread = new Thread(() =>
{
Statistics myClass= new Statistics(path);
list = myClass.getStatistics();
});
thread.Start();
foreach (KeyValuePair<string, string> item in list )
{
listBoxIps.Items.Add(item.Key + item.Value + "\n");
}
}
I want to wait until thread has finish its job and then start the foreach, when I put the foreach in the thread, cross threading error received.
You want thread.Join. But that’s probably not exactly what you are trying to do (because Join will block, in which case why even use a separate thread in the first place). Look into the BackgroundWorker class.