因为猜测这种异常的原因是很常见的。但让我解释一下所面临的确切情况。请找到我的代码块的概述。
Task.Factory.StartNew(()=> Method1());
private void Method1()
{
//A process which loads the file and uploads it to server. If the file was large, it will take some amount of time.
using (var fileStream = System.IO.File.OpenRead(filePath))
{
//Upload file
}
//Once uploads deletes from local.
File.Delete(path);
}
在上传文件之前调用了删除方法,因为我使用了单独的任务。所以我得到进程无法访问文件的异常。
上传结束后我应该删除文件。需要一些建议。