【发布时间】:2020-04-26 13:57:28
【问题描述】:
我收到了错误 The process cannot access the file X because it is used by another process,我很确定这是同一个过程,因为我检查了所有其他打开的应用程序。
这些是我使用这个文件的时间。
...
string jsonString;
jsonString = JsonSerializer.Serialize(hardware);
System.IO.File.WriteAllText(Directory.GetCurrentDirectory().ToString() + @"\HardwareInfo.json", jsonString);
// ^^ This is where I get the exception ^^
...
...
var uploadFile = path + @"\HardwareInfo.json";
using (var localStream = File.OpenRead(uploadFile))
{
await client.UploadAsync(localStream, Path.GetFileName(uploadFile));
}
...
我不知道这是否重要,但它在第二种方法中被异步使用。
提前致谢。
【问题讨论】:
-
client是什么类型?在我看来,当您致电UploadAsync时,您正试图再次读取该文件。 -
var client = new SftpClient(host, int.Parse(port), username, password);这是一个 SftpClient 实例(SshNet)
标签: c# file asynchronous io