B
Ben Callister
i have an application that has a background thread that downloads files from
a remote server and places them within a local directory. additionally, i
have another thread that is running the FileSystemWatcher provided by .NET
which notifies me when a file is created in that directory and then spins
off another worker thread to perform some final processing on the new file.
my problem is that my final worker thread that processes the file CANNOT
begin to process the file UNTIL the file has been FULLY downloaded. yet i
receive the event from FileSystemWatcher early when the file first appears
(but often is still being written to).
so, i was wondering if:
1) is there a way to determine if a file is in use (e.g. file handle count)?
if so, then my worker thread can just wait until the file is no longer in
use?
2) if not, can someone suggest a better alternative implementation to
solving this issue?
*please note that i cannot have the thread that is performing the download
actually trigger the final worker thread itself when it is done writing the
file to disk. this is because i also have the requirement that if a file is
simply copied (e.g. by the user) from another location on the local
computer, that it be picked up and processed by the FileSystemWatcher as
well. therefore, i must use this FileSystemWatcher-based implementation.
many thanks in advance,
ben
a remote server and places them within a local directory. additionally, i
have another thread that is running the FileSystemWatcher provided by .NET
which notifies me when a file is created in that directory and then spins
off another worker thread to perform some final processing on the new file.
my problem is that my final worker thread that processes the file CANNOT
begin to process the file UNTIL the file has been FULLY downloaded. yet i
receive the event from FileSystemWatcher early when the file first appears
(but often is still being written to).
so, i was wondering if:
1) is there a way to determine if a file is in use (e.g. file handle count)?
if so, then my worker thread can just wait until the file is no longer in
use?
2) if not, can someone suggest a better alternative implementation to
solving this issue?
*please note that i cannot have the thread that is performing the download
actually trigger the final worker thread itself when it is done writing the
file to disk. this is because i also have the requirement that if a file is
simply copied (e.g. by the user) from another location on the local
computer, that it be picked up and processed by the FileSystemWatcher as
well. therefore, i must use this FileSystemWatcher-based implementation.
many thanks in advance,
ben