简体   繁体   English

如何将进度监视器传递给几个子程序?

[英]How to pass through the progress monitor to several subroutines?

Suppose I have an API method which is intended to perform long-term operation and which therefore receives monitor as a parameter, like in 假设我有一个API方法,用于执行长期操作,因此接收监视器作为参数,如

org.eclipse.ui.part.EditorPart.doSave(IProgressMonitor monitor)

If I had single operation to do in this method, I would code, for instance, to write an image 如果我在这个方法中有单一的操作,我会编写代码,例如,编写一个图像

imageFile.create(imageInput, false, monitor);

But what if I do SEVERAL long-term sub-routines inside single doSave ? 但是,如果我在单个doSave长期子例程doSave办? How to make that monitor measures each with 50% or something? 如何让每个监视器测量50%或者什么?

imageFile.create(imageInput, false, monitor);
descriptionFile.create(descriptionInput, false, monitor);

Use SubProgressMonitor for each call the methods: 使用SubProgressMonitor为每个调用方法:

monitor.beginText("task", 100);

imageFile.create(imageInput, false, new SubProgressMonitor(monitor, 50));

descriptionFile.create(descriptionInput, false, new SubProgressMonitor(monitor, 50));

The sum of the 'tick' count given to all the sub progress monitors should match the 'tick' count given on the beginTask call. 给予所有子进度监视器的'tick'计数的beginTask应该与beginTask调用给出的'tick'计数相匹配。

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

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