Azevedo Posted May 1, 2017 Share Posted May 1, 2017 (edited) Hey guys! I'm a javascript coder and I have this question about keeping a script running "forever" in the background/tray until the user exit via tray icon or hotkey. If I do a loop like: Do ; statements Until True ; forever or until a user exit from tray or hotkey func myFunc() ; code EndFunc Is it the right way to loop a program "forever"? I mean, in the Do/loop won't it be consuming cpu time while idle? Edited May 1, 2017 by Azevedo Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 It will consume cpu time if you don't put in a short sleep to give the cpu a "breather". What is your end goal? Typically you would run your loop until a certain condition is met, rather than a blanket "forever". Even if it is something you want always on, there are probably better ways of doing it if you can explain the background. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 My goal is write a desktop helper with some hotkeys, menus, etc... I'm not sure how to loop it properly. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 If you're looking for a traymenu-type application, here is a suggestion based on a shortened version of one I run. expandcollapse popup#include <GetHashedPW.au3> Opt("TrayMenuMode",3) ; Default tray menu items (Script Paused/Exit) will not be shown. TraySetToolTip( "All Scripts" ) Local $myReturn = _getHashed() ;returns my hashed PW TrayCreateItem("") #Region Apps=================== $borderApps = TrayCreateMenu("-----Applications-----") $appWiz = TrayCreateItem("AppWiz", $borderApps) TrayCreateItem("", $borderApps) $eventView = TrayCreateItem("Event Viewer", $borderApps) TrayCreateItem("", $borderApps) $services = TrayCreateItem("Services", $borderApps) TrayCreateItem("", $borderApps) $aduc = TrayCreateItem("A.D. Users and Computers", $borderApps) TrayCreateItem("", $borderApps) $gpmc = TrayCreateItem("GPMC", $borderApps) TrayCreateItem("", $borderApps) $dns = TrayCreateItem("DNS", $borderApps) TrayCreateItem("", $borderApps) $comp = TrayCreateItem("Computer Management", $borderApps) TrayCreateItem("", $borderApps) #EndRegion===================== TrayCreateItem("") $reboot = TrayCreateItem("Reboot") TrayCreateItem("") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Switch TrayGetMsg() Case 0 ContinueLoop Case $appWiz ShellExecute("AppWiz.cpl") Case $eventView ShellExecute("Eventvwr.msc") Case $services ShellExecute("Services.msc") Case $aduc ShellExecute("dsa.msc") Case $gpmc RunAs("<admin user>", "mycorp.com", $myReturn, 0, "C:\Network Tools.exe /GPMC") Case $dns RunAs("<admin user>", "mycorp.com", $myReturn, 0, "C:\DNS.bat", "C:\", @SW_HIDE) Case $comp RunAs("<admin user>", "mycorp.com", $myReturn, 0, "C:\Network Tools.exe /COMP") Case $reboot Shutdown(6) Case $exititem Exit EndSwitch WEnd "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 (edited) Thanks @JLogan3o13! just what I was looking for, this example! I'll write my desktop helper based on your example code. Is it better to write the functions before or after the while statement? Edited May 1, 2017 by Azevedo Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 I usually do them at the bottom, personally. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 Thanks! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 Now I checked the cpu usage it is always taking cpu time . Even though it is a small amount. In some autohotkey scripts I wrote they are resident but they take absolutely no cpu time/usage at all, unless its functions are called. Is it something worth a new release of AutoIt with a fix? I don't feel comfortable having idle scripts using cpu time. Can it be fixed somehow? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 I just checked the sample script, as I provided it to you, and show no CPU usage unless I am launching one of the applications. If you are experiencing something different, please post the code you're using. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 You cannot see it using Windows task manager. Try Proccess Explorer instead. Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 Based on this post I wonder if it is possible a new release of Autoit with cpu usage fix. Why ahk scripts can be resident consuming ZERO cpu time and AutoIt scripts can't? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 Yes, I see a .04 usage under Process Explorer. It is so minimal I am not surprised Task Manager doesn't bother to report it. Why, exactly, is this such a deal breaker for you? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 Threads merged. Please stick to one thread until we determine this is actually a "problem", rather than jumping right to yelling for a new version. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 Now I'm recalling why I switched to ahk. Dejavu. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 Because the DEV community doesn't drop everything and make a change to the software just for your liking? How about exhibiting some patience while others weigh in? And if this is the attitude you brought to the forum your last visit, you're more than welcome to rejoin the ahk community. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 (edited) 12 minutes ago, JLogan3o13 said: Why, exactly, is this such a deal breaker for you? I didn't like this answer. You minimized my question... Oh.. it is just 0.04% of cpu time. how silly of me. Edited May 1, 2017 by Azevedo Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 Just now, Azevedo said: how silly of me. Whew, thought I was not being direct enough. The question stands - what lousy system are you working on, in any language, where .4% is something you cannot live with? This is the second thread of yours where you are calling for updates to AutoIt, without providing much in the way of what isn't working for you. Other than your other thread devolving into a discussion on lousy video games, I never saw an answer to that question. My question was an honest and straightforward (and simple, I thought) one: why is .4% a deal breaker? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Azevedo Posted May 1, 2017 Author Share Posted May 1, 2017 (edited) I'm on i7 16Gb ram. That's not the point though. Bah nevermind. Why bother when I already know it won't be addressed. Now you'll start deleting my posts? That does it. I'm out. How did you get moderator status in the first place with that bossy attitude? Edited May 1, 2017 by Azevedo Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 1, 2017 Moderators Share Posted May 1, 2017 (edited) No one is deleting anything. I simply don't understand why you're incapable of answering two simple questions: WHAT isn't working in AutoIt (from thread one) and WHY is the CPU usage of such concern (this thread) - unless there is no basis for your complaint. My "bossy" attitude usually comes out when people state in multiple threads that the language is lacking or needs to be updated, without providing a concrete reason behind it. That said, we'll let others weigh in. If your desire for an update to address this CPU usage is enough to spur Jon into a new development cycle, then hooray for all. If that happens, I will even apologize for hurting your feelings. Edit: Just saw your report, not sure what you think I deleted; I have deleted nothing you have typed, merely merged two threads into one. Edited May 1, 2017 by JLogan3o13 SkysLastChance 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2017 Developers Share Posted May 1, 2017 55 minutes ago, Azevedo said: How did you get moderator status in the first place with that bossy attitude? You want a real piece of bossy/bad attitude? Just reread your posts and try seeing that from our side. 1 hour ago, Azevedo said: Now I'm recalling why I switched to ahk. Dejavu. Do you seriously think we are waiting for this bs? My shirt won't get wet when you simply repeat what you did then, so either try playing nice here or simply bugger off. Jos JLogan3o13 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...
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