c# statusstrip toolstripstatuslabel updates after the process is over

784 views Asked by At

I have a method in which the program cycles through a load of data and I want it to put in the toolstripstatuslabel1 the text loading, but for some reason it does this after it is done loading as opposed to while it is loading. My toolStripProgressBar1 however does update properly. What might I be doing wrong?

toolStripStatusLabel1.Text = "Acquiringdata for: " + name;
toolStripProgressBar1.Minimum = 0;
toolStripProgressBar1.Value = 1;
toolStripProgressBar1.Step = 1;

        for (int i = 8; i < data.Count; i++)
        {
            string newstr = data[i];
            string date = newstr.Substring(0, newstr.IndexOf(","));
            newstr = newstr.Substring(newstr.IndexOf(",") + 1);
            string close = newstr.Substring(0, newstr.IndexOf(","));
            newstr = newstr.Substring(newstr.IndexOf(",") + 1);
            string high = newstr.Substring(0, newstr.IndexOf(","));
            newstr = newstr.Substring(newstr.IndexOf(",") + 1);
            string low = newstr.Substring(0, newstr.IndexOf(","));
            newstr = newstr.Substring(newstr.IndexOf(",") + 1);
            string open = newstr.Substring(0, newstr.IndexOf(","));
            newstr = newstr.Substring(newstr.IndexOf(",") + 1);
            string volume = newstr.Substring(0);

            DataPoint dp = new DataPoint(date, close, high, low, open, volume);
            dataPoints.Add(dp);

            richTextBox1.Text += "New DataPoint Added: \n";

            toolStripProgressBar1.PerformStep();
            toolStripStatusLabel2.Text = (double)(i / (data.Count - 8))*100 + "%";
        }
1

There are 1 answers

0
jister On

The issue here was that I was running the process on my UI thread.