Solved

VB.NET How to Pause, Wait or Timer an Application for X seconds

Posted on 2003-10-31
9
6,046 Views
Last Modified: 2012-08-14
I need to be able to pause execution for 5 seconds, how-to
0
Comment
Question by:mkisow
[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
9 Comments
 
LVL 7

Accepted Solution

by:
RBertora earned 100 total points
ID: 9657683
 Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)



  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Sleep(3000)
    MsgBox("hello")
  End Sub

Regards,
Rob Bertora
0
 
LVL 2

Assisted Solution

by:CuSo4
CuSo4 earned 100 total points
ID: 9658024
Or you can just use this command:

Thread.Sleep(5000)
0
 
LVL 2

Expert Comment

by:CuSo4
ID: 9658059
Oeps, I should heve add it, if you use Thread.Sleep(5000), you need to add the following statement before the rest of your code:

Imports System.Threading
0
Independent Software Vendors: 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 48

Assisted Solution

by:Mikal613
Mikal613 earned 100 total points
ID: 9659186
0
 
LVL 19

Assisted Solution

by:Desp
Desp earned 100 total points
ID: 9662231

Also, it will be better to make the user aware that the application is paused.. to acheive this you can set the Cursor to an Hourglass. and then reset the default cursor after pausing your application... below is some code for this

' CODE BEFORE PAUSE.....
'............
Cursor = Cursors.WaitCursor     ' Show an hourglass Cursor
System.Threading.Thread.Sleep(5000) ' Wait for 5 seconds
Cursor = Cursors.Default ' restore normal cursor
'............
' CODE AFTER PAUSE.....
'
0
 
LVL 5

Assisted Solution

by:KeirGordon
KeirGordon earned 100 total points
ID: 10165717
You might do something more along the lines of

private sub Wait(howlong as integer)
 Cursor = Cursors.WaitCursor
 for x as integer = 0 to howlong*10
  System.Threading.Thread.Sleep(100)
  Application.DoEvents()
 next
 Cursor = Cursors.Default
end sub

.... I think if you just did a 5 second sleep your application would be completely unresponsive.... but with the DoEvents in the above version things will run a bit more smoothly.

I could be wrong ;)

--KG
0
 
LVL 5

Expert Comment

by:KeirGordon
ID: 10165729
Keep in mind the DoEvents takes a 'little' time.... so your 5 seconds might run more like 5.0000001 seconds.... if that matters.
0

Featured Post

Technology Partners: 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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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