Sleep Function

  • Using PB12.5, I recently needed to use the PowerBuilder Sleep function to add a very short pause to a loop. I first started with a half second:

    Sleep(.5)

    This was too much so I lowered it to half that:

    Sleep(.25)

    Even though it's a quarter of a second, I was able to detect that nothing was happening. It seemed as if anything lower than .5 seconds doesn't work. The Sleep method just returns with no actual sleeping.

    To get around this, I had to use the Win32 Sleep function

    SUBROUTINE WinSleep(int dwMilliseconds) Library "kernel32.dll" ALIAS FOR "Sleep"

    A 10th of a second would have sufficed. This routine takes the actual milliseconds as a parameter so we need to use it a bit different than the Sleep function.

    WinSleep(100)

    And just like that, it worked. My loop had enough of a pause to accomplish what it needed to do.