我通过为file is being used by another process
实现using
处理FileStream
的错误。但是,我遇到了Stream was not readable
的错误。
下面是我的代码段:
之前:
正在运行,但遇到“文件正在被另一个进程使用”错误定期
EmailMessage responseMessageWithAttachment = responseMessage.Save(); foreach (var attachment in email.Attachments) { if (attachment is FileAttachment) { FileAttachment fileAttachment = attachment as FileAttachment; fileAttachment.Load(); fileAttachment.Load(AppConfig.EmailSaveFilePath + fileAttachment.Name); FileStream fs = new FileStream(AppConfig.EmailSaveFilePath + fileAttachment.Name, FileMode.OpenOrCreate); responseMessageWithAttachment.Attachments.AddFileAttachment(attachment.Name, fs); } } responseMessageWithAttachment.SendAndSaveCopy();
之后:
遇到“无法读取流”错误
EmailMessage responseMessageWithAttachment = responseMessage.Save(); foreach (var attachment in email.Attachments) { if (attachment is FileAttachment) { FileAttachment fileAttachment = attachment as FileAttachment; fileAttachment.Load(); fileAttachment.Load(AppConfig.EmailSaveFilePath + fileAttachment.Name); using (FileStream fs = new FileStream(AppConfig.EmailSaveFilePath + fileAttachment.Name, FileMode.OpenOrCreate)) { responseMessageWithAttachment.Attachments.AddFileAttachment(attachment.Name, fs); }; } } responseMessageWithAttachment.SendAndSaveCopy();
我正在通过实现for FileStream来处理另一个进程正在使用的文件错误。但是,我遇到了Stream无法读取的错误。下面是我的代码段:之前:...
正在运行,但定期遇到“文件正在被另一个进程使用”错误