Cheetah
Cheetah

Reputation: 14379

Batch processing of files that have changed

I have an application which has a Timer and a FileSystemWatcher in it for batch processing of changed files every 5 minutes for instance.

The FileSystemWatcher raises event when a file is changed and the file path is added to a Queue, only after checking if it already exists in the queue or not.

When the Timer ticks it iterates through the queue, popping each item and processing it; until the queue is empty.

My questions are:

Upvotes: 1

Views: 231

Answers (1)

Jsinh
Jsinh

Reputation: 2579

EDITED : Question 1: I thinks the approach and object you are using for batch processing of files is appropriate as i see. Note: The time interval for processing the changes should be fair enough so that you don't run into any file lock issues or something similar.

Question 2: If the queue is accessed from the same instance then i don't see any issues. You experience locking issues normally with collections if you are accessing it from differnet threads, which is not the case here.

Then again if you encounter that issue or worried for the queue access and thread safety, I would suggest using - Concurrent Collection types

Your question: "What happens if the Timer ticks at the same time that the FileSystemWatcher adds a changed file?" - Answer to this question is - "You will not get any exception or errors and the file changes add item will apprear on next timer tick for processing."

Upvotes: 1

Related Questions