C # window becomes blank when busy & # 8594; Progressbar? But how?

I have a program that performs some copy jobs (via File.Copy), which can take several minutes. When the user brings another window to the foreground, at this time the program window becomes empty, since it does not redraw itself.

Now I want to show the ProgressBar in an additional window in the center of the screen, but this window is also empty.

Therefore, I run it in another thread that did not help.

I'm sure someone has done this before, but I cannot find a working example. Any ideas?

+8
multithreading c # progress-bar winforms
source share
4 answers

The documentation for the BackgroundWorker class has a good example.

+4
source share

You can use the BackgroundWorker class.

See this answer.

0
source share

ChrisF is true. Your lengthy operation should be done in the BackgroundWorker thread. You can use BackgroundWorker to report progress and connect it to the execution line of your form.

0
source share

You need to perform the operation using BackgroundWorker . There are other ways to stream the operation, but this is probably the easiest and will continue to forward messages in the foreground, so Windows does not think your application has stopped responding.

Another option is to use Thread and use Thread.Join to wait for the background task to complete, since Thread.Join also sends standard message pump information to Windows while it waits.

0
source share

All Articles