Solved

What exactly happens when 'Sleeping'

Posted on 2006-07-08
6
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

717 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