Files
XCEngine/docs/api/threading/task-group/iscomplete.md

37 lines
831 B
Markdown
Raw Normal View History

# TaskGroup::IsComplete
```cpp
bool IsComplete() const
```
检查任务组中所有任务是否已完成。
**参数:** 无
**返回:** `bool` - 所有任务完成返回 true否则返回 false
**复杂度:** O(1)
**注意:** 由于实现缺陷,`m_pendingCount` 计数器在任务完成后不会递减,因此此方法在所有任务执行完毕后仍会错误地返回 false。
**示例:**
```cpp
TaskGroup* group = TaskSystem::Get().CreateTaskGroup();
for (int i = 0; i < 100; ++i) {
group->AddTask([i]() { HeavyCompute(i); });
}
// 非阻塞轮询
while (!group->IsComplete()) {
printf("Progress: %.1f%%\n", group->GetProgress() * 100.0f);
Thread::Sleep(500);
}
```
## 相关文档
- [TaskGroup 总览](task-group.md) - 返回类总览
- [GetProgress](getprogress.md) - 获取完成进度