8

I have a program which does some copy jobs (via File.Copy) that could last a few minutes. When the user brings another window to foreground in this time the program window gets blank since it doesn't redraw itself.

Now I want to show a ProgressBar in an extra window in the center of the screen, but that window get's blank too.

So I startet it in another thread which didn't help.

I'm quite sure someone did this before but I cannot find a working example. Any Ideas?

Sergio
  • 28,539
  • 11
  • 85
  • 132
ihavenoaccount
  • 163
  • 1
  • 3

4 Answers4

4

There is nice example in the documentation on BackgroundWorker class.

artplastika
  • 1,972
  • 2
  • 19
  • 38
  • thanks. such things are too hard to find if your're not knowing what exactly you are looking for.... who would have thought that this is a component?^^ – ihavenoaccount Aug 19 '11 at 14:07
0

You can use BackgroundWorker class.

See this answer.

Community
  • 1
  • 1
CB.
  • 58,865
  • 9
  • 159
  • 159
0

ChrisF is correct. Your long operation should be done in a BackgroundWorker thread. You can use BackgroundWorker to report progress, and hook that up to a progress bar on your form.

Daniel Walker
  • 760
  • 6
  • 11
0

You need to thread your operation using a BackgroundWorker. There are other ways to thread the operation, but this one is probably the simplest, and will continue to perform message pumping in the foreground so Windows doesn't think your application has stopped responding.

Another option would be to use a 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.

qJake
  • 16,821
  • 17
  • 83
  • 135