1

I have a small winform application and i put a progress bar on first running form. This progress bar completes in 10 seconds and after progress bar completes the next activity starts like database call.

I want when this progress bar runs for 10 seconds, during this time database call should do its work instead of calling after the progress bar completes.

Can anyone explain or have sample code to explain this technique ??? Thanks in advance.

user3004110
  • 929
  • 10
  • 24
  • 36

3 Answers3

3

Your issue probably arises from the fact that you are running the heavy duty work on the User Interface Thread, so basically you are holding that thread from doing anything.

To solve this issue you need to run on a separate Thread and Control.Invoke the progress bar control when it needs update.

Check out Threading and the UI on VS Magazine.

Alexandru Lache
  • 477
  • 2
  • 14
1

You need to use a background worker!

Do your heavy operation in the background worker thread and on the UI thread keep the progress bar running.

You should find plenty of examples about the usage of a background worker, some here:

http://www.dotnetperls.com/backgroundworker

https://stackoverflow.com/a/15153258/2243584

Community
  • 1
  • 1
toATwork
  • 1,335
  • 16
  • 34
0

There are many good multi-threading tutorials out there that explain in ample detail this question. Googling "winforms thread sync" this is the first one that comes up. Pretty good.

aldosa
  • 327
  • 1
  • 2
  • 9