Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public Sub Sleep(Millaseconds As Long)
Dim EndTime As Long
EndTime = GetTickCount + Millaseconds
Do Until GetTickCount >= EndTime
DoEvents
Loop
End Sub
I wrote this myself and im wondering if this is the "safest" and more effective way to make my bot sleep, for example if i did something like
Send "/join the void"
Sleep(2000)
Send "/join " & strLastChannel
What is this accomplishing?
Quote from: phvckmeh on August 17, 2004, 03:18 AM
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public Sub Sleep(Millaseconds As Long)
Dim EndTime As Long
EndTime = GetTickCount + Millaseconds
Do Until GetTickCount >= EndTime
DoEvents
Loop
End Sub
I wrote this myself and im wondering if this is the "safest" and more effective way to make my bot sleep, for example if i did something like
Send "/join the void"
Sleep(2000)
Send "/join " & strLastChannel
Thats very poor im sorry to say that will eat processor cycles, i suggest using a timer for doing that.
That way the system will generate a timer event after 2 seconds and wont waste valuable processor cycles in a pointless loop.
Also the most efficient sleep function is the raw win32 api:-
VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);
Or the more advanced:-
DWORD SleepEx(
DWORD dwMilliseconds, // time-out interval in milliseconds
BOOL bAlertable // early completion flag
);
The calling thread will enter an efficient wait state using those.
The first api function can be applied to vb quite easily using the standard declare statement which gives you access to the win32 api.
An additional note also those functions will block your main thread in vb for the specified time you pass into the function which is why i again recommend using a timer for doing this:-
Send "/join the void"
Sleep(2000)
Send "/join " & strLastChannel
If you want to efficiently sleep, but also track when window messages come in, consider using one of the MsgWaitForMultipleObjects family. It'll awaken when the time elapses, a message is delivered, or when one of the watched handles becomes signalled.