1.1 KiB
1.1 KiB
TaskGroup::GetProgress
float GetProgress() const;
获取任务组的完成进度。
参数: 无
返回:
float- 0.0 到 1.0 之间的进度值,0.0 表示没有任务或都没有完成,1.0 表示全部完成
线程安全: ✅ 线程安全
示例:
#include "XCEngine/Threading/TaskGroup.h"
#include "XCEngine/Threading/Task.h"
#include <iostream>
#include <chrono>
using namespace XCEngine::Threading;
int main() {
TaskGroup group;
for (int i = 0; i < 4; ++i) {
group.AddTask([i]() {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
});
}
while (!group.IsComplete()) {
float progress = group.GetProgress();
std::cout << "Progress: " << (progress * 100) << "%\n";
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
std::cout << "Final Progress: " << (group.GetProgress() * 100) << "%\n";
return 0;
}
相关文档
- TaskGroup 总览 - 返回类总览
- IsComplete - 检查是否完成