I'm working on a WindowsForm and trying to import data from a file, meanwhile I'd like to display the new data on sreen as soon as I read it in.
My basic code looks like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Read_in();
}
List<Data> _list = new List<Data>();
public void Read_in()
{
using (StreamReader sr = new StreamReader("in.txt"))
{
while (!sr.EndOfStream)
{
Data d = new Data
{
a = sr.ReadLine()
};
_list.Add(d);
Controls.Add(d.pb);
}
}
}
}
class Data
{
public string a;
public PictureBox pb = new PictureBox()
{
BackColor = Color.Red
};
}
The problem is that my data is only displayed when Read_in() is finished. How can I help this?
Here's a post similar to this one, but I couldn't understand it: Why won't control update/refresh mid-process