Sign in to follow this  
Followers 0
St4inL3ss

exiting script takes a while

5 posts in this topic

I have made this small script:

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$exititem = TrayCreateItem("Exit")

TraySetState()

$failures = 0

While 1
    $msg = TrayGetMsg()
    If $msg = $exititem Then Exit
    $var = Ping("www.yahoo.com",1000)
    TraySetIcon("Shell32.dll",50)
    sleep(100)
    
    If ($var >0 AND $var < 500) Then
        TraySetIcon("Shell32.dll",239)
        TraySetToolTip("ping=" & $var)
        sleep(5000)
        $failures=0
    Else
        $failures=$failures+1
        TraySetIcon("Shell32.dll",338)
        TraySetToolTip("ping=" & $var & ",failures=" & $failures )
        sleep(1000)
    EndIf   

WEnd

but when I click Exit from the tray menu, the script doesn't close instanly. It usually takes 2-3 minutes to close. Any ideas why this happens?

Share this post


Link to post
Share on other sites



I need the sleeps to be long. Is there any alternative to make this work?

Share this post


Link to post
Share on other sites

Use TrayEvent mode perhaps. Split sleeps up in little sleeps.

You don't need the sleeps to be long, you need the application do nothing (except get tray messages) for a long time.

Share this post


Link to post
Share on other sites

I changed it using TrayItemSetOnEvent and it works now, thanks.

This is it:

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

$failures = 0

While 1
    $var = Ping("www.yahoo.com",1000)
    TraySetIcon("Shell32.dll",50)
    sleep(100)
    
    If ($var >0 AND $var < 500) Then
        TraySetIcon("Shell32.dll",239)
        TraySetToolTip("ping=" & $var)
        sleep(5000)
        $failures=0
    Else
        $failures=$failures+1
        TraySetIcon("Shell32.dll",338)
        TraySetToolTip("ping=" & $var & ",failures=" & $failures )
        sleep(1000)
    EndIf   

WEnd

Func ExitScript()
    Exit
EndFunc

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