Function Reference


_WinAPI_WaitSystemIdle

Wait both Processor and Disk IO are idle

#include <WinAPISys.au3>
_WinAPI_WaitSystemIdle ( [$bToolTip = False [, $nMaxLoop = Default [, $fSystemPercent = 1.0 [, $fIOPercent = 1.0 [, $iRefresh = 2]]]]] )

Parameters

$bToolTip [optional] to display a tooltip of the Processor or Disk IO usage (Default no display)
$nMaxLoop [optional] max number of evaluations (Default no Check)
$fSystemPercent [optional] the counting will stop if the current Processor usage is below.
$fIOPercent [optional] the counting will stop if the current Disk IO usage is below.
$iRefresh [optional] the time between to evaluation (Default = 2 Sec).

Return Value

Success: the number of time Processor usage was above $fSystemPercent ($fSystemPercent Default is 1.0).
@extended is the number of time Disk IO usage was above $fIOPercent ($fIOPercent Default is 1.0).
Failure: Sets the @error flag if number of evaluation exceed.

Remarks

During the Loops the User inputs are disabled : BlockInput($BI_DISABLE).
Unless strange behavior evaluation for Disk IO Usage percent will not be effective.

Related

_WinAPI_QueryProcessorUsage, _WinAPI_QueryDiskUsage

Example

#pragma compile(AutoItExecuteAllowed, True)

#include <MsgBoxConstants.au3>
#include <WinAPISys.au3>

; create a script which use CPU
Local $sTestAu3 = @TempDir & "\TestSystemIdle.au3"
FileDelete($sTestAu3)
FileWriteLine($sTestAu3, 'For $i = 1 To 20000000')
FileWriteLine($sTestAu3, '$i = $i')
FileWriteLine($sTestAu3, 'Next')

;~ Local $sTestAu3 = @TempDir & "\TestIOIdle.au3"
;~ FileDelete($sTestAu3)
;~ FileWriteLine($sTestAu3, 'For $i = 1 To 100000')
;~ FileWriteLine($sTestAu3, 'FileRead(@ScriptFullPath)')
;~ FileWriteLine($sTestAu3, 'Next')

If @Compiled Then
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sTestAu3 & '"')
Else
    Run(@AutoItExe & " " & $sTestAu3)
EndIf

Local $hTimer = TimerInit()
Local $nSleep = _WinAPI_WaitSystemIdle(True)
Local $iExtended = @extended
Local $sElapse = Round(TimerDiff($hTimer) / 1000, 2)

FileDelete($sTestAu3)

MsgBox($MB_TOPMOST, 'Test duration', $sElapse & " sec (" & $nSleep & "/" & $iExtended & ')')