Files
XCEngine/docs/api/threading/task-group/get-progress.md

1.1 KiB
Raw Blame History

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;
}

相关文档