Sign in to follow this  
Followers 0
Gui

Set timeout for an entire script?

9 posts in this topic

Aye guys. Let's say you want to run a script for X amount of minutes, and then close after that X amount of time has passed. Is that possible?

I'd like to have a 'User Defined' set timeout for the entire script. So if let's say it's been 10 minutes, the script was to stop and GUI would close.

Is it possible in any means?

I'm familiar with TimerInit, and TimerDiff, like :

$timer = TimerInit()
            While TimerDiff($timer) <= 5000 ; 5 seconds
                            Sleep(10)
            WEnd

but I have no idea on how to use it for an entire script. Any help is always meaningful. Thanks!

Regards,

GUI.

Share this post


Link to post
Share on other sites



$init = TimerInit()
While 1
    If TimerDiff($init) > 3000 Then Exit
    Sleep(100)
WEnd

If you have a GUI, open and running, how would that work? You'd need to put it at the end of the loop which is currently running, but if you did that the shutdown would be off.

#include 
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#Include <GuiEdit.au3>
#include <Constants.au3>

GuiCreate("Vid5",300,300,400,200)
$start = GuiCtrlCreateEdit("",10,10,200,200)
$oIE = _IECreateEmbedded()
$Obj = GUICtrlCreateObj($oIE,5,5,200,200)
GUICtrlSetState(-1,$Obj)
GUISetState()

While 1
    $Msg = GUIGetMsg()
        If $Msg = $start Then
            start()
        EndIf
WEnd
    

Func start()
        
    While 
        _IENavigate($oIE,'http://www.google.com')
        ;data;
        
        
        ;more code;
        
        
        
        ;tone more code;
        
    WEnd
        
EndFunc

You couldn't just place that anywhere.

Share this post


Link to post
Share on other sites

You couldn't just place that anywhere.

Ermm... I think it could be done. AFAIK, every Autoit script must have at least 1 running loop, you can place it there. In case of nested loop, use function:

$init = TimerInit()
While 1
    If $some_condition_is_true Then
        While 1
            ;
            ;
            _Close()
        WEnd
    EndIf
    ;
    ;
    _Close()
WEnd

Func _Close()
    If TimerDiff($init) > 5000 Then Exit
EndFunc

Hi ;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

EDIT : Got it working! Sorry had a dumb moment with the function. Anyways I GREATLY appreciate all your help. : )

Edited by Gui

Share this post


Link to post
Share on other sites

EDIT : Got it working! Sorry had a dumb moment with the function. Anyways I GREATLY appreciate all your help. : )

No problem :D


Hi ;)

Share this post


Link to post
Share on other sites

every Autoit script must have at least 1 running loop

Since when?

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Since when?

Errr.. I mean, to keep the script running, otherwise it will exit when it reaches the bottom.. unless one use a very long Sleep(). This is especially true if you use GUI, in which you must constantly check the GUIGetMsg.

But I might be wrong. I'm glad if somebody can help me find another way to idle around without the need to use a While loop.

Sorry for not making myself clear at the first place.


Hi ;)

Share this post


Link to post
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
Sign in to follow this  
Followers 0