File handling in a threadpool

G

Guest

Hi all, I have a Windows service that uses a thread pool and a file watcher.
Everything works well enough except for the problem of a given file being
opened by more than one thread.

What is a good way to make sure that once a given file is opened by a thread
no other threads will open it for processing?
 
D

Dmytro Lapshyn [MVP]

Keep a list of files currently being processed as a thread-safe hashtable.
Each thread will be updating the list with the file it is working on.
Before a thread tries to open a new file, it must check the file is not on
the list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top