I have this Progress Bar class (Testing threading)
public class ProgressBarUpdate
{
//Add getters and setters
static MainGUI theForm = (MainGUI)Application.OpenForms[0];
ProgressBar pBarCur = theForm.pBarCur; //Yes, accessing public for now
bool updateCur = false;
bool stopCur = false;
bool showMax = false;
public ProgressBarUpdate()
{
}
public void resetCur()
{
pBarCur.Value = 0;
}
public void DoCurUpdate()
{
while (!stopCur)
{
if (pBarCur.Value < (pBarCur.Maximum / 10) * 9)
pBarCur.PerformStep();
if (showMax)
{
pBarCur.Value = pBarCur.Maximum;
showMax = false;
}
}
}
public void StopCur()
{
stopCur = true;
}
public void UpdateCur()
{
updateCur = true;
}
public void UpdateToMax()
{
showMax = true;
}
And then I'm calling all of it in a different class A to update the GUI from there:
ProgressBarUpdate updateBar = new ProgressBarUpdate();
Thread currentProgressUpdater = new Thread(new ThreadStart(updateBar.DoCurUpdate));
try
{
currentProgressUpdater.Start();
currentProgressUpdater.Join();
}
catch (Exception)
{
}
And after I run it, I get the dialog where my application has stopped responding (right away) and then it asks me to close. Am I not implementing Threads correctly? Or am I missing a step?