[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

What exactly happens when 'Sleeping'

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
ahammar
Asked:
ahammar
  • 3
  • 3
1 Solution
 
Mark_FreeSoftwareCommented:

sleeping suspends your app,

no code will be executed at all
0
 
ahammarAuthor Commented:
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
 
ahammarAuthor Commented:
which also means that once the timer triggers, it will not trigger again for 57 seconds (42 + 15), right?

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Mark_FreeSoftwareCommented:

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
 
ahammarAuthor Commented:
Ok, I see.  That answers my question.  Thank you1

Cheers!
ahammar
0
 
Mark_FreeSoftwareCommented:

thanks for the points, and happy coding!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now