Files
XCEngine/docs/api/threading/task-group/cancel.md
ssdfasd 7e4c48d4f9 docs: Document stub/not-implemented methods in resources module
Fixed discrepancies between source code and documentation:
- AsyncLoader: Document Initialize() ignores workerThreadCount, Submit() doesn't do actual async loading, Update() is stub
- ResourceManager: Document UnloadUnused() and ReloadResource() are stubs
- ResourceCache: Document OnZeroRefCount() and Flush() are stubs
- ResourceDependencyGraph: Document TopologicalSort() returns empty (stub)
- ResourceFileSystem: Document GetResourceInfo() doesn't fill modifiedTime, EnumerateResources() is stub
- FileArchive: Document Enumerate() is stub
- ResourcePackageBuilder: Document AddDirectory() is stub
- ImportSettings: Document LoadFromJSON/SaveToJSON are stubs
- TextureImportSettings/MeshImportSettings: Document JSON methods are stubs
- TextureLoader/MeshLoader/MaterialLoader/ShaderLoader/AudioLoader: Document GetDefaultSettings() returns nullptr
- AudioLoader: Document ParseWAVData() is stub, Load() doesn't parse WAV headers
- ShaderLoader: Document DetectShaderType/ParseShaderSource are stubs
- MaterialLoader: Document ParseMaterialData() is stub
- Texture: Document Create() mipLevels=0 behavior, GenerateMipmaps() returns false
- Mesh: Document MeshLoader::Load() is example only
- IResourceLoader: Document GetDefaultSettings() returns nullptr for all loaders
2026-03-19 01:16:12 +08:00

46 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::Cancel
```cpp
void Cancel()
```
**注意:** 此方法为**部分实现**,存在已知问题。
取消任务组中所有尚未执行的任务。正在执行的任务将不受影响。
**参数:**
**返回:**
**复杂度:** O(n)
**当前状态:** 此方法会调用各任务的 `OnCancel()` 回调,但不会减少 `m_pendingCount` 计数器。因此调用 `Wait()` 会导致永久阻塞。建议在 `Cancel()` 后使用 `IsComplete()` 轮询或使用带超时的 `WaitFor()`
**示例:**
```cpp
TaskGroup* group = TaskSystem::Get().CreateTaskGroup();
for (int i = 0; i < 100; ++i) {
group->AddTask([i]() {
if (ShouldCancel()) {
return; // 检查取消状态
}
ProcessLongTask(i);
});
}
// 如果用户点击取消按钮
if (userClickedCancel) {
group->Cancel();
printf("Tasks canceled. Progress: %.1f%%\n", group->GetProgress() * 100.0f);
}
// 注意Cancel() 后 Wait() 会永久阻塞,应使用 WaitFor()
group->WaitFor(std::chrono::seconds(1));
```
## 相关文档
- [TaskGroup 总览](task-group.md) - 返回类总览