M
Mo
Hi,
I have a windows service which is watching a directory and when a new
file is added it spawns a new thread and tries to read a file. In
order to check if the file is available for read I have the follwoing
code in the thread to check to see when the file is closed before it
open and reads the content. This is still locking up about 30% of the
time and the thread appears to time out. Does anybody have a good
method of checking if a file is available for read? here is what I
have in my thread to check for file availability
while (!FileAvailable)
{
try
{
fs = new System.IO.FileStream(SourceFilePath +
FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
FileAvailable = true;
}
catch
{
Thread.Sleep(10000);
FileAvailable = false;
}
}
Any suggestions is greatly appreciated.
Thanks,
Mo
..
I have a windows service which is watching a directory and when a new
file is added it spawns a new thread and tries to read a file. In
order to check if the file is available for read I have the follwoing
code in the thread to check to see when the file is closed before it
open and reads the content. This is still locking up about 30% of the
time and the thread appears to time out. Does anybody have a good
method of checking if a file is available for read? here is what I
have in my thread to check for file availability
while (!FileAvailable)
{
try
{
fs = new System.IO.FileStream(SourceFilePath +
FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
FileAvailable = true;
}
catch
{
Thread.Sleep(10000);
FileAvailable = false;
}
}
Any suggestions is greatly appreciated.
Thanks,
Mo
..