Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2009, 01:32 PM
Authorized User
 
Join Date: Jun 2008
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default Creating a wait or pause in my program

I want to be able to create a pause in my program where I can tell it to just wait for a given period of time and then start again. Does anyone know how I can do this?
 
Old January 8th, 2009, 08:45 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default How about Sleep function

Can you try

System.Threading.Thread.Sleep(1000)

it will pause for 1000 milliseconds

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old February 7th, 2009, 05:31 AM
Authorized User
 
Join Date: Dec 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Shasur View Post
Can you try

System.Threading.Thread.Sleep(1000)

it will pause for 1000 milliseconds

Cheers
Shasur
That is a great final answer but for educational purpose here is a method you can play with.

Code:
Sub Nap(NapDuration as DateTime)
    Dim t1 as DateTime = Now
    Dim t2 as DateTime
    While (t2 < t1 + NapDuration)
        t2 = Now()
    End While
End Sub
 
Old February 7th, 2009, 05:37 AM
Authorized User
 
Join Date: Dec 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Note if you want your application to refresh a visible control with t2 during the loop you will have to use Application.DoEvents inside your loop.

This allows the Application to um DoEvents between loops. Otherwise the applcation wont be able to do basic form events until the loop finished.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating binary file compatible with other program wakeup ASP.NET 2.0 Basics 0 October 16th, 2008 03:03 AM
need help with creating a base conversion program sparxxxx C++ Programming 1 April 11th, 2008 03:27 PM
Wait In VB ashes0000 Beginning VB 6 5 February 6th, 2007 11:47 AM
Should I wait for .net 2 androoo ADO.NET 2 November 3rd, 2004 09:07 AM
help me! wait online EdmondWang All Other Wrox Books 1 December 18th, 2003 06:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.