Announcement

Collapse
No announcement yet.

Watch directory using another thread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cliff Nichols
    replied
    BUSTED


    Sorry couldn't help myself

    5 globals can be forgiven (amongst the many out there that I have used)

    Anyways had to razz a bit so hopefully no harm no foul

    anyways for Mike Doty's question, I can not say for sure, but if you can test on a machine you consider "Extremely slow" and do not notice much of an impact, then I say run with it

    Leave a comment:


  • Michael Mattias
    replied
    But, but... that was so long ago, when I was young and foolish!

    Leave a comment:


  • Dave Biggs
    replied
    Well just a few..
    Code:
     ' GLOBAL datanames
    GLOBAL CookiePath AS ASCIIZ * %MAX_PATH
    GLOBAL nChangeEntries AS LONG      ' number of valid entries in the CookieChange array
    GLOBAL CookieChange() AS STRING
    GLOBAL hWndMain       AS LONG      ' because we need to reference it from a thread function
    GLOBAL hDlgAbout      AS LONG      ' when true, the modeless 'About' dialog box is running
    Not that there's anything wrong with that!

    Leave a comment:


  • Michael Mattias
    replied
    Win32(SDK): Internet Cookie Monitor April 25, 2001

    No GLOBALs, no timed looping.

    (Will work with any directory, not just the Cookie directory).

    Leave a comment:


  • Mike Doty
    started a topic Watch directory using another thread

    Watch directory using another thread

    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.

    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
    Last edited by Mike Doty; 22 Feb 2008, 03:26 AM.
Working...
X