Jump to content

exiting script takes a while


 Share

Recommended Posts

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?

Link to comment
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
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...