Results 1 to 9 of 9

Thread: VBscript Sleep

  1. #1
    Join Date
    Apr 2004
    Posts
    7

    Unanswered: VBscript Sleep

    im writing a DTS package and i have am using vbscript to check if a file exists on an ftp server.

    I can't figure out how to make my process sleep b/t checks on if the file exists.

    in vb u can just

    Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

    but i cant seem to find a counterpart in vbscript.

    thanks in advance,
    pete

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    In DTS it is poor programming technique to sleep a thread, due to the threading model that DTS uses. You are much better off to design your package so that it completes one full "cradle to grave" cycle when it executes, then schedule the whole package to execute as often as needed.

    If you want to check for events less than a minute apart, then this requires some creativity, but that is a small price to pay for the simplicity that this programming model buys the developer.

    -PatP

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Have to agree with Pat here....but.....if you really want to....

    There are ways of doing it.... basically you'd set up a loop to check the time and see if the time has progressed

    Code:
    sub sleep(seconds)
      dim start, end
      start = now()
      end = dateadd(s,start, seconds)
      do while now() < end
      loop
    end sub
    Not sure if the dateadd syntax is correct but the theory should be sound. note that this is not really sleeping.... it is not giving up the processor time at all....

    Personally would say follow Pat's advise.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Yeouch! For a single user (MSDE) system, Rokslide's code might be Ok (it would certainly keep the machine busy until the appointed time). For a server, I wouldn't recommend it!

    -PatP

  5. #5
    Join Date
    Apr 2004
    Posts
    7

    Unhappy server

    yah thats why i really needed a sleep. b/c i am running this on a server. i could just loop and chew up the processor but it would basically kill the server while it looped.

    pat, how would u design a package that would do check for a file... and then if its not there check again later??? the only way i could think of is to sleep.

    thanks,
    pete

  6. #6
    Join Date
    Apr 2004
    Posts
    7

    Question calling a batch file

    is there a way i can call an externel batch file or executable that sleeps???

    im not familiar w/ the threading model of DTS... does calling the executable from DTS fork a new process but continues on w/ its own processing? OR does it call the new process and wait for it to return b/f executing the rest of its own code.

    thanks,
    pete

  7. #7
    Join Date
    Apr 2004
    Posts
    7

    Thumbs down fork new process

    well i tried creating a new process that sleeps and calling it from

    Set WshShell = CreateObject("WScript.Shell")
    wshShell.run("XXX")
    set wshShell = nothing

    msgbox("done")


    it showed that a new process if forked and the DTS still continues so alas, i still have no way of sleeping.

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by pete2781
    pat, how would u design a package that would do check for a file... and then if its not there check again later??? the only way i could think of is to sleep.
    I'd write the DTS package so that it checked for the file, and terminated gracefully if the file was not present. Then schedule the package so that it runs frequently, for example every five minutes.

    -PatP

  9. #9
    Join Date
    Apr 2004
    Posts
    7

    Thumbs up thanks pat

    Pat, thats a great idea... thanks a ton. im gonna go try that now... i didnt kno the scheduler could run at intervals like that... im a fresh outta school newb.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •