Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to exit WaitForSingleObject?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00844020
Message ID:
00844238
Views:
16
Thanks for your help Claude. I have been out to the Microsoft site quite a bit lately looking at the info on Sleep and WaitForSingleObject etc. Part of my problem with reading their documentation is that some of their talk about processes and threads gets a bit deep for me. <g>

Anyhow, I'll give it another shot. Thanks again for your help!

>You shouldn't need DoEvents any more - that's what Sleep(0) is doing. DoEvents is probably maxing the processor. I would read up on the Sleep API if you want to find out more about how it works - the MS site is a good source of info and examples...
>>I changed my code a bit to take advantage of the sleep(0) procedure.
>>
>>
>>DECLARE Sleep IN kernel32.dll integer dwMilli
>>
>>DO WHILE !llQuit
>>   = Sleep(0)
>>
>>   * Do my own check for files and processing
>>
>>   DOEVENTS
>>ENDDO
>>
>>
>>(I didn't have the DOEVENTS in my code anywhere before ... I guess this was keeping the DoubleClick suppressed). Anyhow, I noticed in my TaskManager that the CPU performance stays up at 80 - 100% when running the above code ... probably because its constantly looping.
>>
>>Performance wise, things don't seem to be slow ... probably because sleep(0) is sharing its downtime. But it definitely makes it look as though my code is now maxing out the processor. Is this normal?
>>
>>>The 0 lets the processor do other things in the most efficient way in a wait state ...
>>>>What does the Sleep with a value of 0 do?
>>>>
>>>>>How about something like this (from AVFP PostSetup):
>>>>>
>>>>>=PostMessage(hWindow, 16, 0, 0)
>>>>>DO WHILE .T.
>>>>> IF WaitForSingleObject(hWindow, WAIT_INTERVAL) != WAIT_TIMEOUT
>>>>>	EXIT
>>>>> ELSE
>>>>>	Sleep(0)
>>>>> ENDIF
>>>>>ENDDO
>>>>>>I've created a little program that uses FindFirstChangeNotification, FindNext ..., and WaitForSingleObject to monitor a directory. When a file is added to the directory, the program comes to life and converts the file, zips it and moves it to another directory before resuming its monitoring of the directory.
>>>>>>
>>>>>>I had in mind that this would launch at startup on the users machine and just run all day but I'm seeing the need for the user to be able to pause or stop the program.
>>>>>>
>>>>>>Because the program has no UI, I wanted to just add a icon to the system tray and allow the user to double click the icon to pause or stop the program. The problem I'm having is that once program goes into it's wait mode, my icon becomes useless. Double clicking does nothing at that point because my program is off waiting. I could cut down the amount of time that the WaitForSingleObject function waits but won't that eat up a lot more processing time? I don't want this thing to be a resource hog.
>>>>>>
>>>>>>Any ideas on how I can accomplish this? Thanks in advance for any ideas!
>>>>>>
>>>>>>Rodd
Previous
Reply
Map
View

Click here to load this message in the networking platform