Forum > Windows
[SOLVED] How to cleanup ReadDirectoryChangesW operations properly?
d7_2_laz:
Hello ASerge, i did try your example with great interest (such examples are so helpful for users!) and try to summarize my picture what's equal and what's different.
I think the core functionality of monitoring is similar, but simply the method of push back of change info differs a bit.
Your's passes the change info, after GetOverlappedResult, directly back to the Gui (UpdateLog) which is fully appropriate and sufficient for most use cases. Such examples are a valuable source to learn!
Mine is, additionally, using WaitForMultipleObjects and, after the GetOverlappedResult, it passes back the info to the Gui in a deferred way.
By: PostMessage to the parent control (TFldrControl), which stores the data (BufferTheDataViaNotify) in a StringList (where the strings do contain the names, and the objects keep an info about the change type, e.g. "rename"). Then, controlled by a timer, those data are pushed back to the Gui.
Honestly, in a retrospective i do not remember why a thread should be needed for that (should be proven by practice).
If i could do it from the scratch, i would try to use your example as base and extend it a bit for to use buffering (then the using app can decide how to process such changes ... for instance rebuild a list completely or maintain items individually), but without threads.Shouldn't be a big thing-
ASerge:
The method without threads also has its drawbacks. The message queue of the main thread is used to wait for the event. But if you call up some system dialog box, such as opening a file, then it will have its own queue. This means that the event will not be available until the dialog closes.
d7_2_laz:
... so if one relies on that the monitor is independent from possible blocking effects from user interactions,
then the thread approach might be a more desired option. The specific use case each needs to be considered, i think.
Thanks a lot for all your feedbacks ASerge! :)
helmutboeckmann:
--- Quote from: ASerge on May 26, 2021, 06:10:52 pm ---
--- Quote from: d7_2_laz on May 24, 2021, 09:33:54 pm ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// ---- replace by: (SOLUTION): PulseEvent(plocaleventrec(StopEvent.Handle)^.Fhandle );
--- End quote ---
It is a pity that TEvent.Handle is not compatible with Delphi. This leads to such errors.
About the mistakes. In the above code, I didn't see where dwBufLen is initialized. Apparently the random value from the stack turns out to be quite large.
In addition to the differences between Lazarus and Delphi, I will give an example (I did it quickly) where such monitoring can be carried out without additional threads in Lazarus.
--- End quote ---
How can I also monitor the subfolders using the sample program ReadDirChanges.zip?
Thank you.
Regards, Meridian
Navigation
[0] Message Index
[*] Previous page