1

プロシージャ TdwsFileNotifier.Execute で、ReadDirectoryChanges 呼び出しが失敗すると、スレッドは Terminate を呼び出して終了しますが、ループはすぐには終了しません。IMO は、次のように Terminate の直後に中断する必要があります。

   FActive:=True;   
   NameThreadForDebugging('FileNotifier '+AnsiString(FDirectory));
   while not Terminated do begin      
       GetQueuedCompletionStatus(FChangeCP, numBytes, completionKey, FPOverlapped, INFINITE);

       if completionKey<>0 then begin
           if not ReadDirectoryChanges(FDirectoryHandle, @FNotificationBuffer,
                                 SizeOf(TdwsFileNotifierBuffer),
                                 (FMode=dnoDirectoryAndSubTree), FNotifyFilter,
                                 @FBytesWritten, @FOverlapped, nil) then
               Terminate;

     fileOpNotification:=@FNotificationBuffer;
     repeat
        offset:=fileOpNotification^.NextEntryOffset;
        if Assigned(FOnFileChanged) then begin
           notify:=True;
           for i:=0 to High(FIgnoredPaths) do begin
              if StrLComp(@fileOpNotification^.FileName[0],
                          PWideChar(Pointer(FIgnoredPaths[i])),
                          Length(FIgnoredPaths[i]))=0 then begin
                 notify:=False;
                 Break;
              end;
           end;
           if notify then begin
              SetString(fileName, fileOpNotification^.FileName,
                        fileOpNotification^.FileNameLength div SizeOf(Char));
              FQueue.QueueNotification(fileName, fileOpNotification^.Action);
           end;
        end;
        fileOpNotification:=@PAnsiChar(fileOpNotification)[offset];
     until offset=0;
     FBytesWritten:=0;
     FillChar(FNotificationBuffer, 0, SizeOf(TdwsFileNotifierBuffer));

   end else Terminate;
   end;
   FActive:=False;
4

0 に答える 0