获得方法进度百分比 [英] getting a method progress percentage

查看:86
本文介绍了获得方法进度百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,如何获得执行方法的进度百分比.
例如,当我们复制文件时,如何获取变量中复制文件的数量,

当我们的应用程序大小太大,并且需要花费一些时间来加载所需的文件时,我们如何才能了解上传了多少应用程序文件?
假设该应用程序有3 100mb文件,在执行我们的应用程序时需要加载该文件.如何了解上传了多少文件大小以及剩余了多少文件?
您知道吗,我确实希望在第一个表单中有一个进度条控件,该控件显示了要上传的文件数量,并且当所有文件都完全上传后,它会显示一条消息,表明应用程序已准备就绪,可以使用.

我清楚吗?如果我不能很好地解释我的问题,请告诉我.

my question is how can we get progress percentage of acting a method.
for e.g when we are copying a file how can we get the amount of copied file in a variable,
or
when our application size is too big, and it takes a while to load it''s needed files, how can we understand how much of our application files are uploaded?
suppose that the application has 3 100mb files that are needed to load when our application is executed. what is the way to understand how much of file sizes are uploaded and how much is remained?
you know, exactly I want to have a progress bar control in my first form that shows how much of files are uploaded and when all of them is uploaded completely, it shows a message that application is ready to use.

am I clear? if I explain my problem not so good, please tell me.

推荐答案

没有一种(或简单的)知道方式,任何操作的完成率是多少特别是如果您想根据操作的持续时间显示完成进度.每种操作受不同因素的影响.

例如,复制文件受以下因素影响:
-源驱动器类型和速度
-目标驱动器类型和速度
-与驱动器的连接速度
-文件碎片
-碎片的位置,例如在磁盘的外部还是内部
-依此类推

解决此问题的一种方法是定义一个简单的静态类,该类始终使用事件报告操作的进度.进行实际工作的每个操作都可以向此类报告其进度.

操作的进度可能是最佳猜测",例如,您可以根据切片的估计长度将操作拆分为切片.例如,如果中间有一些东西预计可以持续更长的时间,则可以将ome操作切成10%+ 10%+ 40%+ 30%+ 10%的比例.这样,您可以显示粗略的估计,操作的进度.

要计算切片,您必须调查实际操作以获取估计值.

希望这是有道理的.
There is no single (or simple) way of knowing, what is the completion ratio for any operation especially if you want to display the completion progress based on the time the operation is going to last. Each operation is affected by different kinds of factors.

For example, copying a file is affected by following factors:
- source drive type and speed
- target drive type and speed
- connection speed to the drives
- fragmentation of the file
- location of the fragments, are they for example on the outer or inner part of the disk
- and so on and so on

One way to tackle this is to define for example a simple static class which always reports the progress of an operation by using an event. Each operation doing the actual work can report it''s progress to this class.

The progress of the operations can be ''best guesses'', for example you can split an operation to slices based on the estimated length of a slice. For example ome operation could be sliced like 10%+10%+40%+30%+10% if there''s something in the middle which is expected to last longer. This way you can display a rough estimate, how the operation is progressing.

To calculate the slices, you must investigate the actual operations to get the estimate.

Hopefully that made sense.


准确吗?你不能很抱歉让您失望,但请考虑一下:取出大约50个混合大小的文件(一些大,小),然后使用Windows资源管理器将它们从计算机上的一个文件夹复制到另一个文件夹.您将看到一个框,告诉您剩余时间.准确吗?它会改变并上升吗?还是下来?还是下降,然后上升,然后再次下降,然后上升很多,然后停止,然后下降到剩余15秒"一个半小时?

大约从80年代开始,微软就一直在努力实现这一目标……甚至还有一个与之相关的XKCD卡通: http://xkcd.com/612/ [^ ]

如果他们做得不好,您有什么机会?做我们所有的事情:猜测并使用软糖因素!
Accurately? You can''t. Sorry to disappoint, but think about it: Take some 50 mixed sized files (some big, some small) and copy them from one folder on your computer to another using Windows Explorer. You will get a box which tells you the remaining time. Is it accurate? Does it change and go up? Or down? Or down, then up, then down again, then up a lot, then stop, then drop to "15 seconds remaining" for an hour and half?

Microsoft has been trying to get this right since about the eighties...there is even an XKCD cartoon that is relevant: http://xkcd.com/612/[^]

If they can'';t get it right, what chance do you have? Do what we all do: guess and use fudge factors!


我注意到这个问题被标记为c#、. Net 4.0.这意味着您可以选择实现自己的程序集加载器-这样就可以为应用程序加载问题实现非常酷的解决方案.

将单独目录中的程序集加载到新的AppDomain中 [ ^ ]
CLR托管API [
I notice that this question is tagged as c#, .Net 4.0. This means that you have the option of implementing your own assembly loader - which allows you to implement a pretty cool solution to the applicaton loading problem.

Loading Assemblies in Separate Directories Into a New AppDomain[^]
CLR Hosting APIs[^]

Best regards
Espen Harlinn


这篇关于获得方法进度百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆