St4inL3ss Posted February 21, 2009 Posted February 21, 2009 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?
jvanegmond Posted February 21, 2009 Posted February 21, 2009 Hi, the sleeps in your program are too long, they are making your program unresponsive. github.com/jvanegmond
St4inL3ss Posted February 23, 2009 Author Posted February 23, 2009 I need the sleeps to be long. Is there any alternative to make this work?
jvanegmond Posted February 23, 2009 Posted February 23, 2009 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. github.com/jvanegmond
St4inL3ss Posted February 24, 2009 Author Posted February 24, 2009 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now