Azevedo

Resident scripts and cpu time issue

20 posts in this topic

#1 ·  Posted (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 by Azevedo

Share this post


Link to post
Share on other sites



#2 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

My goal is write a desktop helper with some hotkeys, menus, etc...

I'm not sure how to loop it properly.

Share this post


Link to post
Share on other sites

#4 ·  Posted

If you're looking for a traymenu-type application, here is a suggestion based on a shortened version of one I run.

#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

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Azevedo

Share this post


Link to post
Share on other sites

#6 ·  Posted

I usually do them at the bottom, personally.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

Thanks!

Share this post


Link to post
Share on other sites

#8 ·  Posted

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?

Share this post


Link to post
Share on other sites

#9 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#10 ·  Posted

You cannot see it using Windows task manager. Try Proccess Explorer instead.

Share this post


Link to post
Share on other sites

#11 ·  Posted

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?

Share this post


Link to post
Share on other sites

#12 ·  Posted

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#13 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#14 ·  Posted

Now I'm recalling why I switched to ahk. Dejavu.

Share this post


Link to post
Share on other sites

#15 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#16 ·  Posted (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 by Azevedo

Share this post


Link to post
Share on other sites

#17 ·  Posted

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#18 ·  Posted (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 by Azevedo

Share this post


Link to post
Share on other sites

#19 ·  Posted (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 by JLogan3o13
1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#20 ·  Posted

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

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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