Would it be better to use a timer to check for a directory change?
This uses 2 globals and not sure how to get around it to signal thread to end.
Also, this code is a bit different than some posted code so improvements are welcome.
This uses 2 globals and not sure how to get around it to signal thread to end.
Also, this code is a bit different than some posted code so improvements are welcome.
Code:
#DIM ALL #INCLUDE "win32api.inc" GLOBAL gWaitInMilliseconds AS LONG GLOBAL gDirectoryToWatch AS ASCIIZ * 64 FUNCTION PBMAIN AS LONG LOCAL hThread???, var&, h&, x&, lResult& gWaitInMilliseconds = 3000 gDirectoryToWatch = "\keep\email" MKDIR gDirectoryToWatch 'create directory ERRCLEAR THREAD CREATE WatchDirectory(var&) TO hThread??? SLEEP 50 THREAD CLOSE hThread TO lResult h = FREEFILE OPEN gDirectoryToWatch + "\TEST" FOR APPEND AS #h FOR x = 1 TO 5 'write something every second PRINT #h, "MORE" IF ERR THEN ? STR$(ERR) SLEEP 1000 NEXT CLOSE #h gWaitInMilliseconds = 0 'signal thread to end SLEEP 4000 'give thread time to end END FUNCTION FUNCTION WatchDirectory (BYVAL x AS LONG) AS LONG LOCAL lDir AS DWORD, found AS DWORD DO lDir = FindFirstChangeNotification(gDirectoryToWatch, 0, %FILE_NOTIFY_CHANGE_SIZE) Found = WaitForSingleObject(lDir, gWaitInMilliseconds) IF found = 0 THEN 'directory changed BEEP END IF FindCloseChangeNotification(lDir) LOOP UNTIL gWaitInMilliseconds=0 ? "Thread done" END FUNCTION
Comment