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

51 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TaskGroup::GetProgress
```cpp
float GetProgress() const;
```
获取任务组的完成进度。
**参数:**
**返回:**
- `float` - 0.0 到 1.0 之间的进度值0.0 表示没有任务或都没有完成1.0 表示全部完成
**线程安全:** ✅ 线程安全
**示例:**
```cpp
#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 总览](task-group.md) - 返回类总览
- [IsComplete](is-complete.md) - 检查是否完成