Wicked_Caty

Leaving a program idle for a long time

7 posts in this topic

What am I supposed to do, if a program is able for a long time?

My program is idle for 20 minutes, before doing a very tiny task, and then starting all over again.

I tries using Sleep(), but that literally melts my CPU and pushes them up for 20 to 30%. Permanently checking the time costs too much CPU too.

Any other way of doing this? Preferably without taking more than 1% CPU. It also needn't be exactly 20 minutes, everything between 15 and 25 is fine too :D

Thanks!

Share this post


Link to post
Share on other sites



Wicked_Caty,

I run many AutoIt executables that stay idle for long periods - and none of them use any CPU. It sounds as if you have a tight loop while idling which is using up cycles - try adding a Sleep(10) inside the loop. Or post the code you use and we can see exactly how to deal with the problem.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Wicked_Caty,

I think the problem is in line....

Oh, wait, have not seen the code.

kylomas

edit: Shit, there goes M23 and his bionic fingers...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Wicked_Caty,

Your code doesn't do anything...

Func Reminder0()

   While 1

      Sleep(20000)
      SoundPlay(@AppDataCommonDir + "\rem\sound.mp3")

   WEnd

EndFunc

Func Reminder1()

   While 1

      ; variable t0 for desired time
      ; calculation for variable t1 for desired time <--- know how to do that, but this is just an example

      While Not $t0 = $t1

         SoundPlay(@AppDataCommonDir + "\rem\sound.mp3")
         ExitLoop()

      WEnd

   WEnd

EndFunc

kylomas

edit: ExitLoop is not a function, it is a statement.  Please post a runnable reproducer.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

That's not the whole code. And the whole code doesn't matter. That are only the two ways that I've figured out put into two functions. It's about the part within the functions, but what's written outside of it. And it would do something if you add those silly two lines outside of the functions and declare the variables $t0 and $t1

Share this post


Link to post
Share on other sites

See my edit...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

  • Similar Content

    • VIP
      By VIP
      The simple widget shows the percentage of cpu, ram used and the CPU temperature.
      - Sleep Time: 2s for apdate GUI info.
      - Every 30s check, sync and update time for computer.
      - Every 60s auto Reduce Memory.
      - If you want it to run at startup, copy or create shortcut at: "%ProgramData%\Data\Microsoft\Windows\Start Menu\Programs\Startup"
      ;# CPU_Widget_TimeSync.exe ;CRC32: F6640DFA ;MD5: 3283875BA29E7143F1A9AB9018374E08 ;SHA-1: AD85B38BAE15A6962D8E6C1A89B164BE6840C877
      Function code from:
      CPU: 
      RAM:  MemGetStats ( )
      Memory:   _WinAPI_EmptyWorkingSet ()
       
    • InternetMonkeyBoy
      By InternetMonkeyBoy
      Hello.  I need a trick to make a process idle down less than sleep.  I use onevents for almost everything, but the problem is the project I'm working on has almost 50 processes.
      Even at around 1% idle it adds up and there will be more processes added.  What I'm looking to do is get to a C like idle of .03 to .08 cpu.  Any tricks you have will be great and I will post the final code I use.  I love AutoIt, but is does need a cooler name, lol.  Thx.
    • david1337
      By david1337
      Hi guys
      I have a script that runs for about 20 seconds.
      If Outlook.exe is not already open, and I open it while the script is running, I want Outlook to wait until the script is done, and then open.
      Is it possible to set an application in some sort of idle state until the script is done? I want to avoid it from just closing Outlook, and open it again.
       
      Thanks
      David
    • Wiffzack
      By Wiffzack
      #RequireAdmin #include <Timers.au3> #include <GUIConstants.au3> Global $Limit = 5 ; idle limit in seconds Global $objWMIService; Global $Instances; Global $temp; Local $Counter = 0 HotKeySet("{ESC}", "_Quit") AdlibRegister("_CheckIdleTime", 500) ; default 250ms AdlibRegister("_findTemp", 60000) ; default 250ms ; ; Not all system support this function!!! Func findTemp() ;;; Source : http://stackoverflow.com/questions/25139311/autoit-get-cpu-temp-and-put-it-into-a-graph $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi") $Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature") For $Item In $Instances $temp = ($Item.CurrentTemperature - 2732) / 10 ; set the temp Next if $temp > 50 Then ; normal cpu temp from 40 to 60°C ; idle 35 to 40°C $Limit = 1 Else $Limit = 10 EndIf EndFunc ;==>findTemp While 1 Sleep(20) if($Counter == 0) Then Run("C:\Windows\System32\cmd.exe", "", @SW_HIDE) $Counter = 1 EndIf WEnd Func _CheckIdleTime() If (_Timer_GetIdleTime() > $Limit * 1000) Then ProcessWait("cmd.exe") Local $hwnd = WinGetHandle("[REGEXPTITLE:(?i)(.*cmd.*|.*cmd.*)]") ControlSend($hwnd, "", "", "powercfg -setactive a1841308-3541-4fab-bc81-f71556f20b4a{Enter}") else ProcessWait("cmd.exe") Local $hwnd = WinGetHandle("[REGEXPTITLE:(?i)(.*cmd.*|.*cmd.*)]") ControlSend($hwnd, "", "", "powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e{Enter}") EndIf EndFunc ;==>_CheckIdleTime Func _Quit() Exit EndFunc ;==>_Quit The first attempt !!!, to control the power plan through idle. This script should adjust the power plan to the individual situation. This is to slow down the overheat. 
      findTemp() function will only run on supported systems!
      This batch script shows you whether your system support this function:
      If the script does not work,  meaningless values are outputted.
      @echo off for /f "delims== tokens=2" %%a in ( 'wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value' ) do ( set /a degrees_celsius=%%a / 10 - 273 ) echo %degrees_celsius% pause  
    • Wicked_Caty
      By Wicked_Caty
      I've written a small surveillance tool for one of my programs. It shows the time that has already passed, the estimated time until the end, the average time of the steps, and the progress in %.
      It works pretty well, but I want to add some stats. That'd be the usages of the CPU, RAM, network and hard-drive of all threads in %. Basically what you see in the taskmanager, but without the list of every single process.
      I'm aware that there's no in-built function for that, and that I'd need an additional library. Are there any for that? Simply functions that return the stats mentioned above. Thanks!
      Edit:   I run an ASUS R752M with an Intel BayTrail M3540 on Windows 10 64-bits.