关于 NSTask 的程序结构

发布于 2024-08-22 17:05:17 字数 597 浏览 6 评论 0原文

我想运行未知数量(在编译时未知)的 NSTasks,并且我想同时运行未知数量(同样,在编译时最多 8 个)的 NSTasks。所以基本上我循环遍历一个文件列表,生成一个 NSTask,运行它直到运行最大数量的同时任务,每当一个任务完成时,另一个 NSTask 就会启动,直到所有任务都完成。

我的方法是创建一个生成 NSTask 的类,并将其子类化,以便在存在不同的输入(从界面进行的更改)时在这里和那里更改参数。然后超类将运行 NSTask 并有一个 @synthesize 方法返回其进度。这些对象将在上面的重复循环中生成,并显示进度。

这是一个好方法吗?如果是这样,有人可以给我一个简单的例子来说明重复循环的样子吗?我不知道一旦所有对象运行,我将如何引用它们。

for (; !done ;) {
    if (maxValue ≥ currentValue) {
  //Run Object with next file.
  //Set currentValue.
 }
 //display progress and set done to YES if needed and set currentValue to it -1 if needed
}

提前致谢。

I want to run an unknown amount (unknown at compile time) of NSTasks and I want to run an unknown amount (again, at compile time, max. 8) of them simultaneously. So basically I loop through a list of files, generate an NSTask, run it until the maximum of simultaneous tasks are ran and whenever one finishes another NSTask starts until all of them are done.

My approach would be creating a class that generates an NSTask and subclass it to change parameters here and there when there's a different input (changes that are made from the interface). Then the superclass will run the NSTask and will have an @synthesize method returning its progress. Those objects will be generated in the above repeat loop and the progress will be displayed.

Is this a good way to go? If so, can someone give me a quick example of how the repeat loop would look like? I don't know how I would reference to all objects once they're run.

for (; !done ;) {
    if (maxValue ≥ currentValue) {
  //Run Object with next file.
  //Set currentValue.
 }
 //display progress and set done to YES if needed and set currentValue to it -1 if needed
}

Thanks in advance.

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

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

发布评论

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

评论(1

烦人精 2024-08-29 17:05:17

完全没有循环。

为尚未开始的任务创建一个数组,为正在运行的任务创建另一个数组,为已完成的任务创建另一个数组。有一种方法可以从待处理任务数组中提取一个任务,启动(启动)它,并将其添加到正在运行的任务数组中。创建数组并填写待处理任务数组后,调用该方法八次。

任务完成,从 running-tasks 数组中删除该任务并将其添加到 finish-tasks 数组中,然后检查是否还有尚未运行的任务。如果至少有一个,请再次调用 run-another-one 方法。否则,检查是否有任何仍在运行:如果没有,则所有任务都已完成,您现在可以组装结果(如果您尚未实时显示它们)。

There's no loop exactly.

Create an array for tasks not yet started, another with tasks that are running, and another with tasks that have finished. Have a method that pulls one task from the pending-tasks array, starts (launches) it, and adds it to the running-tasks array. After creating the arrays and filling out the pending-tasks array, call that method eight times.

When a task finishes, remove the task from the running-tasks array and add it to the finished-tasks array, then check whether there are any tasks yet to run. If there's at least one, call the run-another-one method again. Otherwise, check whether there are any still running: If not, all tasks have finished, and you can assemble the results now (if you haven't been displaying them live).

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