On my MainForm I start a thread which does some SQL-related work. In the meantime I want a new form to show with a Progressbar to confirm that the program is still responding. The Problem I'm having is that the Progressbar doesn't show the correct values. I want the Progressbar to go from Minimum to Maximum over and over, just to ensure the user that the program isn't stuck. However the Progressbar doesn't appear the way I want it to, because It resets when It's reached 2/3 of it's Maximum value. So the Progressbar is showing values from Minimum to 2/3 of Maximum. Below is a picture of when the Progressbar resets to Value = 0;
The MainForm contains the following code:
List<Table> ContentList = new List<Table>();
using (ConnectingForm CF = new ConnectingForm())
{
CF.StartPosition = FormStartPosition.Manual;
CF.Show(this);
Thread thread = new Thread(() => { ContentList = DBL.LoadSQLData(); });
thread.Start();
DBL.SQLdone = false;
while (!DBL.SQLdone);
this.Focus();
CF.Hide();
}
And the ConnectingForm has the following code:
public ConnectingForm()
{
InitializeComponent();
progressBar1.Value = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = 50;
progressBar1.Step = 1;
timer1.Interval = 25;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < progressBar1.Maximum)
progressBar1.PerformStep();
else
progressBar1.Value = 0;
}
I have also tried to set the Progressbar's value inside the while loop. However the problem still exists: the UI doesn't show the animation of the last 1/3 of the Progressbar Value increase. At the moment the code looks like this:
MainForm:
...
Thread thread = new Thread(() => { ContentList = DBL.LoadSQLData(); });
thread.Start();
DBL.SQLdone = false;
while (!DBL.SQLdone)
{
if (CF.Value == CF.Maximum)
CF.Value = 0;
else
CF.Value += 1;
Thread.Sleep(100);
}
...
While the ConnectingForm looks like this:
public ConnectingForm()
{
InitializeComponent();
progressBar1.Value = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = 20;
progressBar1.Step = 1;
}
public int Value
{
set { progressBar1.Value = value; }
get { return progressBar1.Value; }
}
public int Maximum
{
get { return progressBar1.Maximum; }
}
Which still gives the same results. The Progressbar only show the Value 0 to 2/3, and then it is reset.
I'm hoping that someone can help me figure out what I'm doing wrong. Thanks in advance!