简体   繁体   中英

C# Show a progress bar in a popup window

I need to have a progress bar in a popup window, while my main thread is doing some heavy calculations. I'm using an Oracle API , all the heavy work is done calling 1 function of this API, so I can't use the backgroudworker update becasue I don't have the API's code. I tried to create a new form with an ProgressBar and a Timer, but the timer_Click event is never fired!!(???)

Any Idea??

while my main thread is doing some heavy calculations.

Wrong. Never do any heavy calculations inside your main thread in a Windows application or your users will simply hate you.

If your API doesn't provide a way to report the progress then the best you could do is show some rotating animation while the calculation is in progress because you will not be able to know the exact percentage of work done. So put the calculation inside a BackgroundWorker , show some spinning animation before running the calculation (which should itself be done inside the DoWork event) and hide the animation once the work is done ( RunWorkerCompletedEvent ).

The ProgressBar has a Style property that you could set to Marquee to emulate an infinite progression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM