tags:

views:

184

answers:

2

I created two services. I want to delete a folder, but that folder is used by my first service. When I execute the first service after that I execute the second service it works fine. But when I try to execute both service at the same time it does not work properly.

+5  A: 

Actually, the question should have been "What in the application could prevent folder from deletion by other applications".

Possibilities are:

  1. Your service opens some file in that folder and does not close it. Check all files that you are opening in the service, and close the ones which are in that folder.
    How files are closed depends on how they were opened. If you used CreateFile(), then close with CloseHandle(). If it was TFileStream, then just Destroy it.

  2. Your service has that folder set as the current directory. Choose other directory as a current with SetCurrentDir.

himself
And the answer to the question in the title then would be: You cannot, at least not under Windows. (e.g. Linux allows to delete files and folders that are in use which can be annoying if you are not used to it.)
dummzeuch
+1  A: 

you cannot delete it unless, you can tell the other service by sending message to stop using the folder(or its content) before deleting it.

XBasic3000