Calling a process in another window from a thread to update a progress bar?

I’ve been playing with this for a couple days and can’t get it to work so I’m wondering if I’m doing something wrong or if this isn’t possible.

I have a main window that calls another window with a timer and thread and a progress bar. This of this as a generic progress bar that can be called for any long running process.

The main window makes a call to a method on the progress bar window with a parameter telling it which process to run on the main window. In the run event of the thread, it calls this process which is running in a loop. Inside that loop it updates some properties on the progress bar window which in turn are used to update the progress bar in the timer’s action event.

It seems to work except for one thing. The progress bar window is displayed and the progress bar is update, but the progress bar window remains open and it never returns to the main window.

I’m a little unclear on what you expect to be happening here, because you haven’t said anything to the effect of “the code I have to close the progress window isn’t working”. Do you have such code in your system?

I’m going to attach this same project. You may have to change it slight because in the Process method of the Main window, it is copying a file 100 times. I’m using a rather large file to copy in order to make this process take a little longer.

Archive.zip (6.3 KB)

in wMain.Process you are doing:

wPB.Thread1.Stop

This stops the Thread, so the next two line won’t be reached.

wPB.Close

Could not work, because in this case you are changing the UI from within a thread.

You can delete
wPB.Timer1.Enabled = False

and check in the timer if the thread is running. If it is not, you can do
self.close

Marius, thank you. I think you fixed it for me.