Solved

What exactly happens when 'Sleeping'

Posted on 2006-07-08
6
148 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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