C
cubaman
Hello:
Im workin with an app that checks for incoming files to a given folder
using a FileSystemWatcher object. My problem is that if the file is
too big, the Created event fires before the file is completely copied
to the folder, and it result in IOException, the file is been used by
another process...
I thought that if i could get exclusive acces to the file it means
that the file is already copied in disc.
bool inUse = true;
FileStream strm = null;
do {
try {
strm = new FileStream(fileName, FileMode.Open,
FileAccess.Read, FileShare.None);
strm.Close();
strm.Dispose();
inUse = false;
}
catch (IOException) {
inUse = true;
LogHelper.WriteLog("File " + fileName + " still in
process.");
if(strm != null) {
strm.Dispose();
}
}
} while (inUse == true);
But this code is a never-ending loop. Even if i see that the file is
already copied in the folder, i can't get inUse= true. Maybe cause
FileSystemWatcher have some reference to it...
Any ideas of how to make this code works? Or how to know when the
incoming file is completely copied to destination folder?
Thank you very much!
Oscar Acosta
Im workin with an app that checks for incoming files to a given folder
using a FileSystemWatcher object. My problem is that if the file is
too big, the Created event fires before the file is completely copied
to the folder, and it result in IOException, the file is been used by
another process...
I thought that if i could get exclusive acces to the file it means
that the file is already copied in disc.
bool inUse = true;
FileStream strm = null;
do {
try {
strm = new FileStream(fileName, FileMode.Open,
FileAccess.Read, FileShare.None);
strm.Close();
strm.Dispose();
inUse = false;
}
catch (IOException) {
inUse = true;
LogHelper.WriteLog("File " + fileName + " still in
process.");
if(strm != null) {
strm.Dispose();
}
}
} while (inUse == true);
But this code is a never-ending loop. Even if i see that the file is
already copied in the folder, i can't get inUse= true. Maybe cause
FileSystemWatcher have some reference to it...
Any ideas of how to make this code works? Or how to know when the
incoming file is completely copied to destination folder?
Thank you very much!
Oscar Acosta