Hey Yona, This is a really really funny problem.
If I understand correctly, you are using FileSystemWatcher or some other similar object to monitor the folder.
Each time a file is added or modified, you get an event.
Now the problem is that this event can be raised at a relatively random time, and if you try to write all files that were changed within 2 seconds of each other, you will have many collections of objects.
What I would do is create a List<List<MyFileChangeClass>> , where MyFileChangeClass is any construct you use to track the changed information.
When you process the event to modify the file, create a new MyFileChangeClass with the necessary data and repeat the external list. For each list, make sure that the first MyFileChangeClass has a timestamp of less than 2 seconds before the current file modification; if so, add the file modification to the internal list.
Once you have finished the whole list, add a new List<MyFileChangeClass> to the external list, which is filled only with the current MyFileChangeClass . This ensures that future changes can be associated with the latter, and that you have all groups of modifications that occurred within 2 seconds of each other.
All around, I would enable the lock - perhaps ReaderWriterLockSlim using TryEnterWriteLock() .
I hope this helps - if you need more information, please let me know, but obviously you know a little about what you are doing, and maybe you just needed a little logical help, because this is a strange problem.
Good luck
Adam