F
Frederik Jensen
Hi,
How do I lock a directory for access in a multithreaded application?
I have Thread1 and Thread2. Thread1 wants to delete a directory. The thread
checks to see whether or not the directory is empty. If it is empty it
deletes the directory. However, Thread2 wants to put files in the directory.
The problem is when this occurres:
1) Thread1 finds that the directory is empty
2) Thread2 puts a file in the directory
3) Thread1 tries to delete the directory, but an exception is thrown as the
directory is not empty.
I have looked at the System.Threading.Monitor class but cannot figure out
how to lock the directory as it cannot be passe into the Enter method.
Any ideas of how to accomplish this otherwise simple matter.
In advance, thx.
How do I lock a directory for access in a multithreaded application?
I have Thread1 and Thread2. Thread1 wants to delete a directory. The thread
checks to see whether or not the directory is empty. If it is empty it
deletes the directory. However, Thread2 wants to put files in the directory.
The problem is when this occurres:
1) Thread1 finds that the directory is empty
2) Thread2 puts a file in the directory
3) Thread1 tries to delete the directory, but an exception is thrown as the
directory is not empty.
I have looked at the System.Threading.Monitor class but cannot figure out
how to lock the directory as it cannot be passe into the Enter method.
Any ideas of how to accomplish this otherwise simple matter.
In advance, thx.