mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-24 20:34:29 +08:00
refactor(storage): 将文件存储读取操作改为异步模式
- 使用 await using 替代 using 确保异步资源正确释放 - 优化文件读取流程以支持异步IO操作 - 提高文件存储组件的异步处理能力
This commit is contained in:
parent
a29a484834
commit
4cfc5d3505
@ -207,7 +207,7 @@ public sealed class FileStorage : IFileStorage
|
|||||||
|
|
||||||
// 读取文件内容可以使用异步IO,但要注意锁范围
|
// 读取文件内容可以使用异步IO,但要注意锁范围
|
||||||
string content;
|
string content;
|
||||||
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
await using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
using (var sr = new StreamReader(fs, Encoding.UTF8))
|
using (var sr = new StreamReader(fs, Encoding.UTF8))
|
||||||
{
|
{
|
||||||
content = await sr.ReadToEndAsync();
|
content = await sr.ReadToEndAsync();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user