Currently I try to improve the design of two windows services (C#).
Service A produces data exports (csv files) and writes them to a temporary directory.
So the file is written to a temporary directory that is a sub dir. of the main output directory.
Then the file is moved (via File.Move
) to the output directory (after a successful write).
This export may be performed by multiple threads.
Another service B tries to fetch the files from this output directory in a defined interval.
How to assure that Directory.GetFiles()
excludes locked files.
Should I try to check every file by creating a new FileStream (using (
Stream stream = new FileStream("MyFilename.txt", FileMode.Open)
) as described here.Or should the producer service (A) use temporary file names (*.csv.tmp) that are automatically excluded by the consumer serivce (B) with appropriate search pattterns. And rename a file after the move was finished.
- Are there better ways to handle such file listing operations.