Jump to content

simple loop using 99% CPU?


Recommended Posts

I have a simple app that starts on user login/system start up. It check the last time the user scanned and if it is less than 7 days quits.

If the last scan was over 7 days it idles about until it sees the log out window and then asks the user if they want to scan the computer before shut down.

The problem I'm having is that if the last scan is over 7 days while it is idle it seems tobe taking up about 99% CPU!

Code below, can someone tell me why my code is sucking up CPU resources?

#include <GUIConstants.au3>
#Include <date.au3>
#NoTrayIcon
$lastscan = IniRead(@ScriptDir & "\scans.ini","scan date","last scan","")

If _DateDiff('d',$lastscan,_NowCalc()) <= 7 Then
    Exit 0
EndIf

While 250
;------   USER CLICKS LOG OFF   ------;
    If WinExists("Log Off Windows") Then
        If _DateDiff( 'd',$lastscan,_NowCalc()) > 7 Then
            $ScanFirst = MsgBox(36, "ScanBoot", "It has been over a week since the last full system scan." & @CRLF & "Would you like ScanBoot to scan your computer now?" & @CRLF & "ScanBoot will restart your computer when finished.", 30)
            If $ScanFirst = 6 OR $ScanFirst = -1 Then
                Run(@ScriptDir & '\scanboot.exe')
                Exit 0
            Else
                Shutdown(0)
            EndIf
        Else
            Exit 0
        EndIf
    EndIf
;------   USER CLICKS SHUTDOWN   ------;    
    If WinExists("Shut Down Windows") Then
        WinKill("Shut Down Windows")
        If _DateDiff( 'd',$lastscan,_NowCalc()) > 7 Then
            $ScanFirst = MsgBox(36, "ScanBoot", "It has been over a week since the last full system scan." & @CRLF & "Would you like ScanBoot to scan your computer now?" & @CRLF & "ScanBoot will restart your computer when finished.", 30)
            If $ScanFirst = 6 OR $ScanFirst = -1 Then
                Run(@ScriptDir & '\scanboot.exe')
                Exit 0
            Else
                Shutdown(0)
            EndIf
        Else
            Exit 0
        EndIf
    EndIf
Wend

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Link to comment
Share on other sites

There was my confusion :">

I thought while 1 was every millisecond, so I figured if I made it 250 it would loop every 250 milliseconds...

Cheers for the help.

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

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...