Solved

What exactly happens when 'Sleeping'

Posted on 2006-07-08
6
145 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
Access 2016 VB code 9 86
VB6 Compile Compatibility Issue 4 40
Sending a email via excel using vba 6 58
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now