简体   繁体   English

C#进度条未与下载同步(WebClient类)

[英]C# progress bar not synced with download (WebClient class)

I am coding a system which has a small FTP module included inside, it's not the main feature at all, but needed... 我正在编写一个系统,其中包含一个小的FTP模块,它根本不是主要功能,但需要......

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... 我必须将进度条与WebClient类事件DownloadProgressChangedEventHandler和AsyncCompletedEventHandler链接,进度条增量正常,并且ASyncCompletedEventHandler启动MessageBox(按预期),问题是进度条看到加载太慢...

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. 我的MessageBox弹出100%(由事件处理程序启动),但是当MessageBox弹出我的进度条仅为+ -80%(但.VALUE真的是100)时,第一个虽然我有,但是他们添加了一个Windows Vista中的“平滑”效果,相对于它的真实价值,它会降低进度条的速度。

If any of you have experienced the same problem thanks for your help. 如果您有任何人遇到同样的问题,感谢您的帮助。

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. 对于那些想要了解的人来说,Vista实际上为加载栏更改添加了“平滑”,它看起来像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. 我在Windows XP上尝试过,当数值达到100时,条形图达到100%。在Vista上,看起来他们已经决定将“加载”分解为延迟X.

Before you display your message box, call Application.DoEvents() to force all the pending Windows queued messages to be processed. 在显示消息框之前,请调用Application.DoEvents()以强制处理所有挂起的Windows排队消息。 Your progress bar is probably not getting a chance to paint itself one last time before the message box displays. 您的进度条可能没有机会在消息框显示之前最后一次绘制自己。

为什么不在显示消息框的同一DownloadProgressChangedEventHandler事件处理程序中将进度条值设置为100%?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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