开发者

Weird IOException with File.Copy: Non-existing file allegedly in use by another process

开发者 https://www.devze.com 2023-01-22 07:57 出处:网络
This is driving me nuts. I retrieve a bunch of emails from a mailbox and save them as files in a folder.

This is driving me nuts.

I retrieve a bunch of emails from a mailbox and save them as files in a folder. There is currently just one mail in the mailbox (this specific mail is not the problem, tried others as well). After retrieval I concatenate the subject of the mail with a unique GUID-string, save it as a file and create another copy of this file in a different folder. This repeatedly gives me an IOException saying that the DESTINATION FILE could not be accessed (since it's allegedly being used by another process). The destination file doesn't exist at this point so it cannot be in use.

Hope anyone can help or maybe give a hint.

Thanks in advance.

Regards, Kevin

EDIT (more info)

        private static void _backupMailFile(string sourceFile, string destinationFile)
        {开发者_JAVA百科
            log.Info(String.Format("Archiving mail file '{0}' to '{1}'", sourceFile, destinationFile));

            try
            {
                File.Copy(sourceFile, destinationFile);
            }
            catch (Exception ex)
            {
                log.Error("Error while archiving mail: " + sourceFile, ex);
            }
        }

sourceFile = "D:\Development\POP3toSCSM\POP3toSCSM\bin\Debug\TempMails\AW_ Outlook Web App Light-47459c48-8c8c-4c51-be63-e6e2ddcc54d3.eml"

destinationFile = "C:\MailIn\Archive\AW_ Outlook Web App Light-47459c48-8c8c-4c51-be63-e6e2ddcc54d3.eml"

The folder "C:\MailIn\Archive" is empty at this point.

Permissions are valid.

Thanks again.


It's either the Chilkat component (doubt that) or my wrapper class around its 'LoadEml'-method. As soon as I add System.Threading.Thread.Sleep(250) after the last mail was retrieved from the mailbox, everything works just fine. But wouldn't you agree that there's nothing wrong with the destination path as opposed to what the exception message reads?

EDIT Guess I was wrong :-(

Here comes the stack trace:

StackTrace = " bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n bei System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)\r\n bei System.IO.File.Copy(String sourceFileName, String destFileName)\r\n ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号