Function Posted November 5, 2007 Share Posted November 5, 2007 Hello, I'm trying to create some menus for the tray icon in my autoitscript and I've been getting 100% cpu usage running this code, making the menu's non responsive. Can someone help point out the error in my code? Thank you. CODE#include <Constants.au3> Opt("WinTitleMatchMode",2) Opt("SendKeyDelay", 0) Opt("SendKeyDownDelay", 0) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) $help = TrayCreateItem("&Help") $seperator1 = TrayCreateItem("") $windowspy = TrayCreateItem("&Window Spy") $reload = TrayCreateItem("&Reload This Script") $edit = TrayCreateItem("&Edit This Script") $seperator2 = TrayCreateItem("") $pause = TrayCreateItem("&Pause Script") $exit = TrayCreateItem("E&xit") TraySetState() #cs HotKeySet("{ESC}", "DoIt") Func DoIt() ;Some Func EndFunc #ce While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $help Run (@ScriptDir & "\AutoIt3.chm") Case $msg = $windowspy Run (@ScriptDir & "\Au3Info.exe") Case $msg = $reload Sleep(100) ;?? Case $msg = $edit Run ("notepad.exe " & @ScriptFullPath) Case $msg = $pause Sleep(100) ;?? Case $msg = $exit ExitLoop EndSelect WEnd Also if someone could give me a tip how to implement the reload and pause script portions of my code, I'd greatly appreciate it. Thank you I'm running the latest autoit on windows xp Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 Why do you have this in there while you are not using events ? Opt("TrayOnEventMode", 1) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Function Posted November 5, 2007 Author Share Posted November 5, 2007 Actually, that fixed it. Thank you. I was originally going to go through the other route of creating tray icon menu's. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 Actually, that fixed it. Thank you. I was originally going to go through the other route of creating tray icon menu's.Moved to Support SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Function Posted November 5, 2007 Author Share Posted November 5, 2007 100% CPU Usage is still a bug, no? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 100% CPU Usage is still a bug, no?no, why ?TrayGetMsg() returns @error = 1 because its in event mode and thus isn't doing a 10 ms sleep...Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Function Posted November 5, 2007 Author Share Posted November 5, 2007 As the code stands, it gives me 100% CPU usage. Try it and see if you can replicate this Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 As the code stands, it gives me 100% CPU usage. Try it and see if you can replicate thisI know and have given the answer but will be a bit more detailed:Normally TrayGetMsg() has a built-in 10 ms sleep to allow other processes to take the CPU, but in your case the TrayGetMsg() errors out due to the Eventmode setting, thus doesn't do the 10ms sleep.This results in the loop not being paused at all.Better explanation ?Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 $msg = 0It was just doing a loop. Thats what caused the 100% usage for me.Also what was the Continue loop etc. for. Took it out. Couldn't find a reason. Your exit also didn't work, changed that.-snip-Updated a few things. You also needed to get rid of Opt("TrayOnEventMode", 1), and Opt("TrayMenuMode",1). Causing your tray menu not to work.This should not be needed as explained in my previous post.... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Sardith Posted November 5, 2007 Share Posted November 5, 2007 Okay, thank you jos. I didn't check to just see if that corrected the problem. But in that script above, not deleted.. his exit function didn't work or his tray menu functions. [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
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