Jump to content

Processor Usage


mucitbey
 Share

Recommended Posts

Hi,
 

#NoTrayIcon
#Include <Timers.au3>

HotKeySet("{ESC}", "On_Exit")

While 1
    If _Timer_GetIdleTime() > 6300000 Then
        Run("Closer.exe")
        While _Timer_GetIdleTime() > 500
            Sleep(10)
        WEnd
        ProcessClose("Closer.exe")
    EndIf
    Sleep(10)
    $timer = TimerInit()
    Do
        Until TimerDiff($timer) >= 600000
        $iFileExist = FileExists("\\ANKSERVER\ank\Tools\csb.ini")
        If $iFileExist Then
        Run("C:\RedStone\Tools\Message.exe")
    Else
    EndIf
WEnd

Func On_Exit()
    Exit
EndFunc

How can I reduce the CPU usage of this code, is there any way I can help with this? Thank you in advance for your help. The code I tried with AddlibRegister didn't work, or I couldn't.

Link to comment
Share on other sites

Hi mucitbey :)

The solution is to move the 2nd Sleep(10) between Do and Until, which will reduce drastically the CPU usage :

#NoTrayIcon
#Include <Timers.au3>

HotKeySet("{ESC}", "On_Exit")

While 1
    If _Timer_GetIdleTime() > 6300000 Then
        Run("Closer.exe")
        While _Timer_GetIdleTime() > 500
            Sleep(10)
        WEnd
        ProcessClose("Closer.exe")
    EndIf
    ; Sleep(10)
    $timer = TimerInit()
    Do
        Sleep(10) ; <=======
    Until TimerDiff($timer) >= 600000
    $iFileExist = FileExists("\\ANKSERVER\ank\Tools\csb.ini")
    If $iFileExist Then
        Run("C:\RedStone\Tools\Message.exe")
    EndIf
WEnd

Func On_Exit()
    Exit
EndFunc

 

Edited by pixelsearch
Link to comment
Share on other sites

How can we do the same?

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <Misc.au3>

_Singleton(@ScriptName, 0)
HotKeySet("{ESC}", "On_Exit")

$lastPos = MouseGetPos()
$lastMove = TimerInit()

Opt("TrayMenuMode", 3)

_ST()

Func _ST()
    Flash()
    TraySetState($TRAY_ICONSTATE_SHOW)
    While 1
        $curPos = MouseGetPos()
        If($lastPos[0] == $curPos[0] And $lastPos[1] == $curPos[1]) Then
            If( TimerDiff($lastMove) > 250000) Then
                MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1))
            EndIf
        Else
            $lastPos = $curPos
            $lastMove = TimerInit()
        EndIf
    WEnd
EndFunc

Func Flash()
    TraySetState($TRAY_ICONSTATE_FLASH)
    Sleep(1000)
EndFunc

Func On_Exit()
    Exit
EndFunc

 

Link to comment
Share on other sites

What is this script supposed to do?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Like previously, just put a small Sleep (100) inside the loop.  While we are there, you do not need to put () around a If. It is not necessary.  Also == is for comparing case sensitive strings, not numbers.  Use = instead.  So your code should look like this :

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <Misc.au3>

_Singleton(@ScriptName, 0)
HotKeySet("{ESC}", "On_Exit")

$lastPos = MouseGetPos()
$lastMove = TimerInit()

Opt("TrayMenuMode", 3)

_ST()

Func _ST()
    Flash()
    TraySetState($TRAY_ICONSTATE_SHOW)
    While 1
        Sleep (100)
        $curPos = MouseGetPos()
        If $lastPos[0] = $curPos[0] And $lastPos[1] = $curPos[1] Then
            If TimerDiff($lastMove) > 250000 Then MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1))
        Else
            $lastPos = $curPos
            $lastMove = TimerInit()
        EndIf
    WEnd
EndFunc

Func Flash()
    TraySetState($TRAY_ICONSTATE_FLASH)
    Sleep(1000)
EndFunc

Func On_Exit()
    Exit
EndFunc

 

Link to comment
Share on other sites

1 hour ago, Nine said:

Like previously, just put a small Sleep (100) inside the loop.  While we are there, you do not need to put () around a If. It is not necessary.  Also == is for comparing case sensitive strings, not numbers.  Use = instead.  So your code should look like this :

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <Misc.au3>

_Singleton(@ScriptName, 0)
HotKeySet("{ESC}", "On_Exit")

$lastPos = MouseGetPos()
$lastMove = TimerInit()

Opt("TrayMenuMode", 3)

_ST()

Func _ST()
    Flash()
    TraySetState($TRAY_ICONSTATE_SHOW)
    While 1
        Sleep (100)
        $curPos = MouseGetPos()
        If $lastPos[0] = $curPos[0] And $lastPos[1] = $curPos[1] Then
            If TimerDiff($lastMove) > 250000 Then MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1))
        Else
            $lastPos = $curPos
            $lastMove = TimerInit()
        EndIf
    WEnd
EndFunc

Func Flash()
    TraySetState($TRAY_ICONSTATE_FLASH)
    Sleep(1000)
EndFunc

Func On_Exit()
    Exit
EndFunc

 

Thanks Nine,
Once again excellent approach, excellent result. Thanks also for your information and referrals.

Link to comment
Share on other sites

5 hours ago, mucitbey said:

If the mouse does not move for 5 minutes, move the mouse to prevent the system from shutting down.

You may want to look into this if all you want to do is keep a system awake.  There are lots of deep discussions in there on how to keep a system active while stuff is running in the background.

 

 

Link to comment
Share on other sites

9 hours ago, BigDaddyO said:

You may want to look into this if all you want to do is keep a system awake.  There are lots of deep discussions in there on how to keep a system active while stuff is running in the background. 

 

 

Thanks BigDaddy,
I've been using this gui for 6 months without problems, the only problem was CPU usage, which was solved by @pixelsearch and @Nine.
It's good to have @Autoit and valuable forum members.

Link to comment
Share on other sites

  • 1 month later...

Hi,

I want to change the wait value ($ stay) on this code according to time. I tried to do it with If, but I couldn't solve the problem, anybody have any ideas? Thank you.

#NoTrayIcon
#Include <Timers.au3>

HotKeySet("{ESC}", "On_Exit")

While 1

If @HOUR < 16 Then
    $stay = 10000 ; 10 minute (600000) (I shortened the time to be able to test.)
Else
    $stay = 60000 ; 90 minute (5400000)(I shortened the time to be able to test.)
EndIf

    If _Timer_GetIdleTime() > $stay Then
        Run("Close.exe")
        While _Timer_GetIdleTime() > 500
            Sleep (10)
        WEnd
        ProcessClose("Close.exe")
    EndIf

$timer = TimerInit()
    Do
        Sleep(10)
        Until TimerDiff($timer) >= 600000
        $ifEx = FileExists("\\ANKSERVER\ank\Tools\csb.ini")
        If $ifEx Then Run("C:\RedStone\Tools\Message.exe")
WEnd

Func On_Exit()
    Exit
EndFunc

What I'm trying to do is; I want to set the waiting time to 90 minutes until 16:59 and 10 minutes after 17:00

Edited by mucitbey
Link to comment
Share on other sites

Few problems here :

1- @HOUR returns a string (see help file).  You should convert it to number with Int() before.

2- Your do...until has a value larger than the $stay, no wonder it doesn't work for your test.

3- If you want to check for 16:59, you should use <= not just <

 

Link to comment
Share on other sites

40 minutes ago, Nine said:

Few problems here :

1- @HOUR returns a string (see help file).  You should convert it to number with Int() before.

2- Your do...until has a value larger than the $stay, no wonder it doesn't work for your test.

3- If you want to check for 16:59, you should use <= not just <

 

Understood thanks.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...