Jump to content

Help me pause program


Recommended Posts

Hi all,

I program a tool with 2 "Start" and "Stop" button (status of program depends on $status variable). When a program started, if condition is valid, it do something and sleep after 10 minutes.

But when I press "Start", sometimes I cannot stop program by pressing "Stop" button. Maybe, because I use SLEEP() function, so I cannot press "Stop".

Help me solve this problem. I wanna this program can stop at any time when the program has run.

$delay = 600000

Func AutoRun()
    While 1
        Select 
        Case $status = "start"
            If <condition expression> Then
                ; do something, code here
            EndIf
            Sleep($delay)
        Case $status = "stop"
            ExitLoop
        EndSelect
    WEnd
    
EndFunc

Thanks in advance,

Edited by konani
Link to comment
Share on other sites

Something like this?

Func AutoRun()
    Local Const $delay = 600000
    Local $timer = TimerInit() - $delay
    While 1
    Select
            Case $status = "start" And TimerDiff($timer) >= $delay
                If <condition expression> Then
                    ; do something, code here
                    $timer = TimerInit()
                EndIf
                Sleep(50)
            Case $status = "stop"
                ExitLoop
    EndSelect
    WEnd
EndFunc
Exit

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Something like this?

Func AutoRun()
    Local Const $delay = 600000
    Local $timer = TimerInit() - $delay
    While 1
    Select
            Case $status = "start" And TimerDiff($timer) >= $delay
                If <condition expression> Then
                    ; do something, code here
                    $timer = TimerInit()
                EndIf
                Sleep(50)
            Case $status = "stop"
                ExitLoop
    EndSelect
    WEnd
EndFunc
Exit

Thank you. But it don't work, because TimerDiff($timer) >= $delay is always false.
Link to comment
Share on other sites

When you say "program" is this some other program (like another script or executable) or are you referring to the script itself?

You'd have to use a hotkey for what you want.

EDIT: Also, why bother putting a boolean expression that will always be false?

$status = "start" And TimerDiff($timer) >= $delay

Given this condition, it doesn't matter what value $status has if 'TimerDiff($timer) >= $delay' is always false. The end result will always be false.

Edited by omikron48
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...