Here is some sample code in which the
waitformultipleobjects does continuous notifications. I
created the example as a standard module.
Option Explicit
Public Const WAIT_FAILED = &HFFFF
Public Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1
Or &H8 Or &H10 Or &H100
Public Const INFINITE = &HFFFF
Public Const WAIT_OBJECT_0 = &H0
Public Declare Function FindFirstChangeNotification
Lib "kernel32" Alias "FindFirstChangeNotificationA"
(ByVal lpPathName As String, ByVal bWatchSubtree As Long,
ByVal dwNotifyFilter As Long) As Long
Public Declare Function FindNextChangeNotification
Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Public Declare Function WaitForSingleObject
Lib "kernel32" (ByVal hHandle As Long, ByVal
dwMilliseconds As Long) As Long
Public Declare Function WaitForMultipleObjects
Lib "kernel32" ( _
ByVal nCount As Long, lpHandles As Long, ByVal
bWaitAll _
As Long, ByVal dwMilliseconds As Long) As Long
Sub Main()
Dim strTgtDir1 As String, strTgtDir2 As String,
varRtnCode, lngNumNotifyDirs As Long
Dim lngNotificationHandle(), lngDirToProcess As Long
strTgtDir1 = "C:\Documents and Settings\All
Users\Documents\My Pictures"
strTgtDir2 = "C:\Documents and Settings\All
Users\Documents\My Music"
'Setup initial notifications
lngNumNotifyDirs = 0
ReDim Preserve lngNotificationHandle(lngNumNotifyDirs +
1)
lngNotificationHandle(0) = FindFirstChangeNotification
(strTgtDir1, True, FILE_NOTIFY_CHANGE_ALL)
lngNumNotifyDirs = lngNumNotifyDirs + 1
ReDim Preserve lngNotificationHandle(lngNumNotifyDirs +
1)
lngNotificationHandle(1) = FindFirstChangeNotification
(strTgtDir2, True, FILE_NOTIFY_CHANGE_ALL)
'When one of the objects becomes signalled the wait
function
'returns with the index of the array element that
changed.
'
RestartScan:
Do
lngDirToProcess = WaitForMultipleObjects
(lngNumNotifyDirs, lngNotificationHandle(1), False,
INFINITE)
If varRtnCode = WAIT_FAILED Then GoTo Finished
lngDirToProcess = lngDirToProcess - WAIT_OBJECT_0
If lngDirToProcess >= 0 Then
'Go process the directory
Exit Do
End If
'Pause before looping again
varRtnCode = WaitForSingleObject(lngNotificationHandle
(1), 500&)
DoEvents
DoEvents
DoEvents
Loop
'Copy files to a backup drive
'Call sf_DirProcessFiles(strSearchSpec, strScanCmd,
colFileNames)
'Start notification check for next time around
varRtnCode = FindNextChangeNotification
(lngNotificationHandle(lngDirToProcess))
GoTo RestartScan
Finished:
End Sub