问题
I am coding a system which has a small FTP module included inside, it's not the main feature at all, but needed...
I must link the progressbar with the WebClient class event DownloadProgressChangedEventHandler and AsyncCompletedEventHandler, the progressbar increment is ok, and the ASyncCompletedEventHandler launch a MessageBox (as intended), the problem is that the progress bar see to load too slow...
problem :
My MessageBox pop at 100% (launched by the event handler), BUT when the MessageBox pop my progress bar is only at +-80% (but the .VALUE is really 100), the first though I had was that they have added a "smooth" effect in Windows Vista which slow down the progressbar relatively to it's true value.
If any of you have experienced the same problem thanks for your help.
回答1:
For those of you who want to know, Vista actually add a "smoothing" to the loadingbar change, it look like the "Tweening effect" of Flash.
I tried on Windows XP and the bar reach 100% exactly when the value reach 100. On Vista it look like they have decided that the "loading" would be splitted over a delay X.
回答2:
Before you display your message box, call Application.DoEvents() to force all the pending Windows queued messages to be processed. Your progress bar is probably not getting a chance to paint itself one last time before the message box displays.
回答3:
Why not simply set the progress bar value to 100% on the same DownloadProgressChangedEventHandler event handler that displays the message box?
来源:https://stackoverflow.com/questions/3024354/c-sharp-progress-bar-not-synced-with-download-webclient-class