Define event and detecting event by VB6 program (No GUI form, an exe program running in the background all tiime)
Posted on 2006-05-14
I want to use a vb6 program (simple program, no GUI, no form), that is constantly
run in the background (use scheduler to run). that will wait for 1 event to occur.
The event means if certain 'file' in a given folder is occured. (either being just created,
or something is appended to it). OS will trigger a event notification to my program
(e.g. wait when file = "c:\inetpub\ftproot\abc_xxx.txt" is created by ftp process)
my program. (in a pudo code format:)
1: Option explicit
3: sub main()
5: set event_to_listen = event_file_created("c:\inetpub\ftproot\abc_xxx.txt")
6: ' I assume event_to_listen is defined here first, ...
8: call listen_event
9: msgbox " get it, wait for next event "
10: go to next_event
11: end sub
13: sub listen_event
15: ' listing to a defined event x --> associated to a file (created, appended, or just touched by reading it
16: ' then do some actions, wait for next event (same event).
17: on change event_to_list then
18: debug.print " event detected at " & now()
19: ' do someting with it when finished, delete the file
20: kill "c:\inetpub\ftproot\abc_xxx.txt"
21: exit sub
23: end sub ' /*sub listen_event */
Q: How do you accomplish above logic without using the 'sleep' function that wait for fixed
number of seconds, then go back to wait again?
A completed sample code will appreciate.
(I believe many people may have the similar questions on how to get a control mechanism for this type of
situations. Please give me some clear path and suggestions.... )