我有创建pdf的功能,然后通过附件中的邮件发送。
创建pdf的功能:
public string CreatePdf()
{
try
{
using (document = new Document())
{
if (File.Exists(filePath))
{
workStream.Dispose();
File.Delete(filePath);
}
// LOGIC to Create PDF
return filePath;
}
}
catch (Exception)
{
throw;
}
finally
{
document.Close();
document.Dispose();
workStream.Close();
}
}
要添加到附件:
myMail.attachment = new Attachment(new CreatePdf());
当我第一次创建文件时,它被创建正常,但是当我再次尝试创建pdf时,我在File.Delete(filePath)
The process cannot access the file because it is being used by another process.
我看到了其他类似的问题,但无法确定需要关闭的内容,因为我关闭了所有内容。