Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / September 2003



Tip: Looking for answers? Try searching our database.

Issues with WaitForMultipleObjects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Wright - 29 Sep 2003 17:20 GMT
       lngDirToProcess = WaitForMultipleObjects
(lngNumNotifyDirs, lngNotificationHandle
(lngNumNotifyDirs - 1), False, INFINITE)

The above line is giving me headaches. It does two things
wrong. (1) It waits and signals my handle properly the
first time only. After that, it keeps signling even when
the only other code in the loop is a
FindNextChangeNotification. I even tried closing the
event and creating a new one and it keeps signaling even
thought there is no activity in the directory that I'm
monitoring. How do I get it to reset the event so it will
not continue looping? I'm using VB6 on Windows XP.

And (2), I receive a WAIT_FAILED result if I provide
anything other than the address of the last element in my
list. i.e. if I have 3 events, i must code
lngNotificationHandle(2) as the list to watch. I thought
the address of the first element should be provided. Does
anyone know why this is happening?
alpine - 29 Sep 2003 17:53 GMT
>        lngDirToProcess = WaitForMultipleObjects
>(lngNumNotifyDirs, lngNotificationHandle
[quoted text clipped - 16 lines]
>the address of the first element should be provided. Does
>anyone know why this is happening?

I believe you will need to provide more of your code along with the
API declares you are using before anyone can provide much of an
answer.

HTH,
Bryan
____________________________________________________________
New Vision Software                   "When the going gets weird,"
Bryan Stafford                     "the weird turn pro."
alpine_don'tsendspam@mvps.org     Hunter S. Thompson -  
Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas
Greg Wright - 30 Sep 2003 06:21 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.