进度状态报告模式

发布于 2024-07-08 01:44:56 字数 126 浏览 5 评论 0原文

我正在实现需要显示进程栏(或进度百分比)的长时间运行的进程。 长时间运行的过程的整体逻辑很复杂(各种分页数据检索),因此,我最终在代码中的不同位置硬编码了大量百分比。

在更新完成百分比时,什么被认为是最佳设计模式?

I am implementing long running processes that require to a process bar - or progress percentage - to be displayed. The overall logic of the long running process is complex (various paged data retrieval), and as a result, I end up hardcoding lots of percentages in various places within the code.

What are considered as the best design patterns when it comes to update a completion percentage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人海汹涌 2024-07-15 01:44:56

我发现 JFace 中使用的模式 IProgressMonitor 效果很好。 通过查看课程,您可能会获得一些见解。 要查看的其他类是 ProgressMonitorDialogIRunnableWithProgress。 您还可以在这篇文章中找到一些帮助。

I've found the pattern used in JFace around IProgressMonitor to work out pretty nicely. You might gain some insight by having a look at the class. Additional classes to look at are ProgressMonitorDialog and IRunnableWithProgress. You may also find this article of some help.

有深☉意 2024-07-15 01:44:56

如果您事先知道要执行的任务的“长度”,并且有办法知道您已经完成了多远,则应该让进度条确定百分比。 例如,如果您必须处理已知数量的文件,请将此数字提供给构建进度条。 然后,在此过程中,栏可以轮询进程,或者进程可以告诉栏它已经走了多远(以文件数量为单位)。 该栏可以根据这两个值计算百分比。 这就是 Java 中的标准进度条 的工作原理。

If you know in advance the 'length' of the task you're going to perform, and have a way of knowing how far along you are, you should let the bar determine the percentage. For example, if you have to process a known number of files, give this number to the progress bar on construction. Then, during the process either the bar can poll the process, or the process can tell the bar how far along it is (in number of files). The bar can compute the percentage from these two values. This is how the standard progress bar in Java works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文