I have a Windows service running on Windows Server 2008 R2 Standard Edition. It's a .NET 4.0 application which processes binary files and moves processed files to a different folder on the same volume. File system is NTFS. The issue is with the following code:
try
{
if (File.Exists(srcFileName))
{
File.Move(srcFileName, dstFileName);
}
}
catch (Exception ex)
{
log.Error("Failed to move file.", ex);
}
Paths srcFileName
and dstFileName
have following forms: D:\src_dir\fileX.bin
and D:\dst_dir\fileX.bin
. The log
is log4net logger object. Files are read for processing with File.ReadAllBytes(srcFileName)
.
The problem is that although code works as expected most of the time, occasionally some files are copied instead of being moved to the destination folder and there are no errors recorded in the log. Looking through the log it seems that everything works fine, but some files appear in both source and destination folders. It appears that the issue is related to server load, as it seems to happen when RAM usage goes over 30 GB (from available 32 GB) and average disk queue goes over 2.
I would appreciate any idea what might cause this behavior, especially absence of exception when move fails. Is there a way to be sure that move operation completed successfully?