views:

10

answers:

1

How to lock the directory that is beign processed in a thread ? and The Wait to write a new set of file to the directory after the folder is released by the thread that started procesing the folder?

A: 

Assuming windows (though the same likely applies on other OSs): there isn't a great way to do this using windows file system attributes. Instead I normally use empty files with specific names to achieve this.

For instance, create a file called: folder.lock. If that file is present, your other threads should treat the folder as locked. They can implement a file system watcher to watch for when this file is deleted and get that to get the invoke the next action for when the folder is released.

If you have multiple threads potentially locking it then you could include a thread identifier in the file or file name, and have your threads check the lock specifically for their own identifier.

CodeBadger