I have a custom form with a custom progress bar, spawned in the main class(main thread). Then I spawn a thread and send it a ThreadStart function. This thread start function should update the progress bar in the custom control, but doesnt.:
class MyClass
{
......
//Custom form with progress bar
public CustomFormWithProgressBar statusScreen = new CustomFormWithProgressBar(0);
//thread to use
private Thread myThread;
.....
//Linked to a button to trigger the update procedure.
void ButtonPressEvent(.......)
{
//create a sub thread to run the work and handle the UI updates to the progress bar
myThread = new Thread(new ThreadStart(ThreadFunction));
myThread.Start();
}
.....
//The function that gets called when the thread runs
public void ThreadFunction()
{
//MyThreadClass myThreadClassObject = new MyThreadClass(this);
//myThreadClassObject.Run();
statusScreen.ShowStatusScreen();
for (int i = 0; i < 100; i++ )
{
statusScreen .SetProgressPercentage(i);
Thread.Sleep(20);
}
statusScreen.CloseStatusScreen();
}
Now my statusScreen form just sits and does nothing. No updates occur. But i have confirmed that the sub thread is indeed created and while i am in ThreadFunction, i am runnin on the new thread. Determined this through the Thread window in visual studio.
Why are my updates to the progress percentage of the status screen not being shown? How can i get my updates to push new values to the progress screen and have it show live?
Please note that the integer values being send into the status screen functions represent a percentage of completion. The Thread.Sleep is simply to see the updates if/when the happen.
Note this is not a re-drawing issue. i call Invalidate when the progress percentage is passed into the custom progress bar