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
46 lines
1.1 KiB
Markdown
46 lines
1.1 KiB
Markdown
# 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) - 返回类总览
|