Solved

What exactly happens when 'Sleeping'

Posted on 2006-07-08
6
147 Views
Last Modified: 2011-09-20
When I use the Sleep API, does all code execution stop?
For example:
If I use the Sleep Api inside a timer control that is set for 15 seconds (15000 ms) that sleeps for 42 seconds, does the timer trigger again even though it is still sleeping, or does it resume timeing from where it left off after it is done sleeping?

ie...
Private Sub Timer1_Timer() 'set at 15000 (15 seconds)
If x = true then
     Sleep (42000) ' (42 seconds)
End If

End Sub

If x is true when the timer triggers, and it goes into sleep, does the timer stop timing until the sleep session is over then start again, or does it keep timing and trigger again after sleep is over or what?
In the example above, the timer would normally trigger 2 times, and then have 3 seconds left before it triggered again after it was done sleeping, or would it go into sleep immediately, sleep for 42 seconds, then finish the rest of it's 15 seconds before triggering again?

I hope that makes sense....

Thanks!
ahammar
0
Comment
Question by:ahammar
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17064928

sleeping suspends your app,

no code will be executed at all
0
 
LVL 23

Author Comment

by:ahammar
ID: 17064982
So that means that the timer quits timing also which means in the example above, the timer would trigger, app would suspend for 42 seconds, then after the 42 seconds was up, wait 15 seconds, then trigger again...right?

Thanks,
ahammar
0
 
LVL 23

Author Comment

by:ahammar
ID: 17064989
which also means that once the timer triggers, it will not trigger again for 57 seconds (42 + 15), right?

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 17065006

that's right

example to test:

add one timer (Timer1)
disable it

add this code:

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
   Timer1.Interval = 5000
   Timer1.Enabled = True
   Sleep 5000
   MsgBox "test2"
End Sub

Private Sub Timer1_Timer()
   MsgBox "Test!"
End Sub



app will "hang" for 5 seconds (no messages processed at all)
than messagebox
after 5 more seconds another messagebox
0
 
LVL 23

Author Comment

by:ahammar
ID: 17065091
Ok, I see.  That answers my question.  Thank you1

Cheers!
ahammar
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17065454

thanks for the points, and happy coding!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question