SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Pause for a Minute

By Steve Jones, 2002/09/26

Total article views: 6489 | Views in the last 30 days: 18

Pause For a Minute

Introduction

Recently I was writing a script that performed a number of things, including a brief service shutdown (not SQL). However there was an issue in shutting down the services because the applications had been built to bring up a dialog box if users were still connected to the application. However, if I waited about 45 seconds or so, the disconnections would occur and I could finish shutting down the app.

I complained to the vendor, but it didn't do much good. All my rants on poor programming practice were listened to and I was politely informed that was the way things were.

Arrrrrrrrrrggggggggghhhhhhhhhhhhhhhhhhhhhhhhh!!!!!!

Never fear, I came up with a workaround that I would like to share.

The Solution

I decided to dig through the documentation for VBScript and find something to help me. I first looked at the time function, which would give me the current time, but rejected that for the need to parse the values and do crazy time related math.

Then I stumbled on the timer function. This returns the number of seconds that have elapsed since midnight on the machine. Aha! Just what I need. I decided to implement this with a simple loop and some arithmatic to create my one minute timer. Here's the script:

Dim starttime, exittime, x

x = 0
' Save the start time
starttime = timer

' Calculate the end time
exittime = starttime + 60

' loop until the exit time is reached
do while timer < exittime
   x= x + 1
loop
That's it, a simple pause implemented.

Conclusions

A really simple script, but one that stumped a few admins around here. Not that you might need it, but this sometimes comes in handy if you are working with a process that might not respond immediately. You could use this to even retry some event after a minute has passed.

I know this could be improved and shortened, but I included a few extra lines for clarity. I've found it's helpful to not make leaps in programming, especially for beginners. I could have dropped this to a couple lines, but this seemed clearer. I could have made this a function and would have in any DTS script.

There is also a bug here. If you are planning on using this anywhere near midnight, DO NOT. It will not run correctly if you start it in the 11:58, 11:59 range. Better to schedule things well before or after this time.

As always I welcome feedback on this article using the "Your Opinion" button below. Please also rate this article.

Steve Jones
©dkRanch.net August 2002
Return to Steve Jones Home

 

By Steve Jones, 2002/09/26

Total article views: 6489 | Views in the last 30 days: 18
Your response
 
 
 
Like this? Try these...

UN*X History

By Steve Jones | Category: The Lighter Side
| 2,302 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com