【发布时间】:2020-08-23 10:58:13
【问题描述】:
我有这个函数每分钟调用一次,有时它会在代码中以其他方式触发。
static async Task WriteFileAsync(string file, string content)
{
using (StreamWriter outputFile = new StreamWriter(file))
{
await outputFile.WriteAsync(content);
}
}
有时我会收到此错误,但并非总是如此,它是非常随机的。
System.IO.IOException: 'The process cannot access the file 'hello.json' because it is being used by another process.'
【问题讨论】:
-
告诉我们你调用WriteFileAsync的方法,你应该等待WriteFileAsync
标签: c# .net multithreading asynchronous