WaitForTimer Method Example

This macro creates 3 asyncronous wait-type objects via WaitForTimer, each with different timout values, and all are set to continuously fire their events after every timeout interval. These are added to a Waits object, and in a loop, Waits.Wait(0) is called. As each timeout expires, a note is written to a text file, which is displayed at the close of the macro.

Sub Main

Msgbox "This demo takes about a minute to run..."

 

On Error GoTo handler

Open "c:\WaitForTimerDemo.txt" for Output as #1

 

'set up the necessary System and Session objects...

Dim sys as Object, sess as Object

Set sys = createobject("Extra.System")

'Assumes an open session...

Set sess = sys.ActiveSession

 

Dim w1 as Object, w2 as Object, w3 as Object

Dim waits as Object

 

'Get a Waits collection object....

set waits = sys.Waits

 

'Use WaitForTimer to retrieve wait-type objects

'that will signal their event repetitively at various

'intervals. Note that syntax "Set obj =..." is

'crucial for this....

Set w1 = sess.WaitForTimer(3000, true)

Set w2 = sess.WaitForTimer(5000, true)

Set w3 = sess.WaitForTimer(7000, true)

 

id1 = waits.Add(w1)

id2 = waits.Add(w2)

id3 = waits.Add(w3)

 

Dim nCount as Integer

 

Do While nCount < 30

'wait forever until an event fires...

retval = waits.Wait(0)

 

Select Case retval

Case id1

print #1, "short " & Now

Case id2

print #1, "medium " & Now

Case id3

print #1, "long " & Now

End Select

 

nCount = nCount + 1

Loop

 

Close #1

 

'display the results....

Shell("Notepad c:\WaitForTimerDemo.txt")

 

Exit Sub

handler:

Msgbox Error$, , "Line" & Str(Erl())

Reset

End Sub