![]() |
FindFirstChangeNotification Thread
Hi,
nur mal ne globale Frage, hat mal jemand, FindFirstChangeNotification unter Vista Ultimate ausprobiert? Also, unter XP funktionierts hier tadelos, nur unter Vista, werd ich wenn ich Glück habe mal ab und zu über eine Änderung informiert, meistens jedoch gar nicht... Hat sich beim Aufruf unter Vista was entscheidendes geändert oder ist das einfach ein Fehler? Gruss s! |
Re: FindFirstChangeNotification Thread
Zitat:
Delphi-Quellcode:
Naja wie gesagt unter XP kein Thema nur unter Vista klappts leider nicht mehr.
procedure TWatcherThread.Execute;
// There appears to be a bug in win 95 where the bWatchSubTree parameter // of FindFirstChangeNotification which is a BOOL only accepts values of // 0 and 1 as valid, rather than 0 and any non-0 value as it should. In D2 // BOOL was defined as 0..1 so the code worked, in D3 it is 0..-1 so // fails. The result is FindF... produces and error message. This fix (bodge) is // needed to produce a 0,1 bool pair, rather that 0,-1 as declared in D3 const R : array [false..true] of BOOL = (BOOL (0), BOOL (1)); var A : array [0..2] of THandle; // used to give the handles to WaitFor... B : boolean; // set to true when the thread is to terminate begin SetName; B := false; A [0] := FDestroyEvent; // put DestroyEvent handle in slot 0 A [1] := FChangeEvent; // put ChangeEvent handle in slot 1 // make the first call to the change notification system and put the returned // handle in slot 2. A [2] := FindFirstChangeNotification (PChar(FDirectory), R[fSubDirectory], FFilters); repeat // if the change notification handle is invalid then: if A [2] = INVALID_HANDLE_VALUE then begin // call the OnInvalid event // wait until either DestroyEvent or the ChangeEvents are signalled case WaitForMultipleObjects (2, PWOHandleArray (@A), false, INFINITE) - WAIT_OBJECT_0 of // DestroyEvent - close down by setting B to true 0 : B := true; // try new conditions and loop back to the invalid handle test 1 : A [2] := FindFirstChangeNotification (PChar(FDirectory), R[fSubDirectory], FFilters) end end else // handle is valid so wait for any of the change notification, destroy or // change events to be signalled case WaitForMultipleObjects (3, PWOHandleArray (@A), false, INFINITE) - WAIT_OBJECT_0 of 0 : begin // DestroyEvent signalled so use FindClose... and close down by setting B to true FindCloseChangeNotification (A [2]); B := true end; 1 : begin // ChangeEvent signalled so close old conditions by FindClose... and start // off new conditions. Loop back to invalid test in case new conditions are // invalid FindCloseChangeNotification (A [2]); A [2] := FindFirstChangeNotification (PChar(FDirectory), R[fSubDirectory], FFilters) end; 2 : begin // Notification signalled, so fire the OnChange event and then FindNext.. // loop back to re-WaitFor... the thread Synchronize (InformChange); FindNextChangeNotification (A [2]) end; end until B; // closing down so chuck the two events CloseHandle (FChangeEvent); CloseHandle (FDestroyEvent) end; Vielleicht hat ja jemand was, das auf Vista und XP funktioniert. Vielen Dank s! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:26 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz