BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cannot delete directory after calling FindCloseChangeNotific

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Nov 20, 2006 4:44 pm    Post subject: Cannot delete directory after calling FindCloseChangeNotific Reply with quote



I've written a small FileMonitor thread which monitors for file changes
in a certain directory.
I've used standard FindFirstChangeNotification and
FindCloseChangeNotification. The problem is that after the thread
executes, I can't delete the monitored directory until I close the
whole application. A call to FindCloseChangeNotification returns True,
which means that Windows successfully closed the monitor handle, but
still when I try to delete that (empty) folder I get an I/O 32. The
code for the thread is very small, so I'll post it here as a whole:

-----------------------------------------------------------
constructor Create(Suspended: Boolean=False); override;
begin
inherited;
FreeOnTerminate=True;
end;

procedure TFileMonitor.Execute;
var
H: Cardinal;
begin
H := FindFirstChangeNotification(PChar(FPath), False,
FILE_NOTIFY_CHANGE_LAST_WRITE or FILE_NOTIFY_CHANGE_FILE_NAME);
if H = INVALID_HANDLE_VALUE then
Terminate
else
try
while not Terminated do
begin
WaitForSingleObject(H, INFINITE);

if not FileExists(FFileInfo.LocalFilePath) then
begin
Terminate;
break;
end;

Synchronize(...);

if not FindNextChangeNotification(H) then
begin
Terminate;
break;
end;
end;
finally
FindCloseChangeNotification(H)
end;
end;
-----------------------------------------------------------

Has anyone had a similar problem?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.