Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy ReadDirectoryChangesW, with only FILE_NOTIFY_CHANGE_LAST_WRITE filter, does signal more than one event on file editing?
    primarykey
    data
    text
    <p>I am monitoring in separate thread application configuration file, which in some cases may be INI in another XML or another. Code of thread monitoring directory (in Delphi) is something like this:</p> <pre><code>procedure TWatcherThread.Execute; type PFileNotifyInformation = ^TFileNotifyInformation; TFileNotifyInformation = record NextEntryOffset: DWORD; Action: DWORD; FileNameLength: DWORD; FileName: WideChar; end; const BufferLength = 65536; var Filter, BytesRead: DWORD; InfoPointer: PFileNotifyInformation; Offset, NextOffset: DWORD; Buffer: array[0..BufferLength - 1] of byte; Overlap: TOverlapped; Events: array[0..1] of THandle; WaitResult: DWORD; FileName, s: string; begin if fDirHandle &lt;&gt; INVALID_HANDLE_VALUE then begin Filter := FILE_NOTIFY_CHANGE_LAST_WRITE; FillChar(Overlap, SizeOf(TOverlapped), 0); Overlap.hEvent := fChangeHandle; Events[0] := fChangeHandle; Events[1] := fShutdownHandle; while not Terminated do begin FillChar(Buffer,SizeOf(Buffer),0); if ReadDirectoryChangesW (fDirHandle, @Buffer[0], BufferLength, TRUE, Filter, @BytesRead, @Overlap, nil) then begin WaitResult := WaitForMultipleObjects(2, @Events[0], FALSE, INFINITE); if WaitResult = WAIT_OBJECT_0 then begin InfoPointer := @Buffer[0]; Offset := 0; repeat NextOffset := InfoPointer.NextEntryOffset; FileName := WideCharToString(@InfoPointer.FileName); if (InfoPointer.Action = FILE_ACTION_MODIFIED) and (CompareText(FileName, 'MyConfig.ini') = 0) then begin //read changes in config or INI file // Do Action.. refresh runtime flags end; PByte(InfoPointer) := PByte(DWORD(InfoPointer) + NextOffset); Offset := Offset + NextOffset; until NextOffset = 0; end; end; end; end; end; </code></pre> <p>Why it signals at least 2 times and how to get correct signal when some flag in config file was changed and was saved?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload