Jump to content

Recommended Posts

Posted (edited)

I've got a little problem with one of my script. For some reason, and that ONLY at night, the script goes to 50% of my CPU load.

I'll give you a little heads up on what my script is doing, the script modify a list every 30 minutes between 8h am and 16h30 Monday to Thursday, on friday it modify the list from 8h30 to noon.

At night I want the script to either desactivate or just go to sleep.

Here is the code.

While 1
    AdlibEnable("CheckWindows")
    $NextStart = _TimeToTicks() + 30 * 60 * 1000
    $NewTime = _TicksToTime($NextStart, $Hour, $Mins, $Secs)
    $Now = _NowTime(5)

    If _TimeToTicks() >= _TimeToTicks("08","00","00") And _TimeToTicks() <= _TimeToTicks("16","30","00") Then
        If _TimeToTicks() >= _TimeToTicks("12","00","00") And _TimeToTicks() <= _TimeToTicks("13","00","00") Then
            $NewStart = (60 - @MIN) * 60 * 1000
            Sleep($NewStart)
        EndIf
        $Start = @MIN
        CheckDay()
        $End = @MIN
        $NewStart = (30 - ($End - $Start)) * 60 * 1000
        Sleep($NewStart)
    Else
        While 1
            AdlibDisable()
            $NewStart = _DateDiff('s', @YEAR & "/" & @MON & "/" & @MDAY & " 16:30:00", @YEAR & "/" & @MON & "/" & @MDAY + 1 & " 08:00:00")
            $NewStart = $NewStart * 60 * 1000
            Sleep($NewStart)
            If _TimeToTicks() >= _TimeToTicks("08","00","00") And _TimeToTicks() <= _TimeToTicks("16","30","00") Then
                ExitLoop
            EndIf
        WEnd
    EndIf
Wend

Right now I thought my problem was with the Adlib function, but I just added a AdlibDisable and it doesn't change anything.

Can anybody tell me what would be the best solution at night.

Thanks and Cheers

Edited by AllSystemGo
Posted

I would like to know if there is a simple way to no execute a line in debug mode!! What I mean is let say that at the end of my script I make a reboot, I don't want that to be execute when until I compile the script.

Cheers

Posted

$debug = "1" ; Use IniRead to read this value from an external ini file with settings, or $CmdLine to read this from command prompt -- whatever

If $debug = "1" Then

; do things

EndIf

Posted

If you want to determine that based on whether the script has been compiled or not (like running in SciTE with F5):

If @Compiled Then
    MsgBox(64, "RunLine", "Running compiled .exe: " & @ScriptName)
Else
    MsgBox(64, "RunLine", "Running uncompiled script: " & @ScriptName)
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

Is it because I didn't explain my problem the proper way an no one understand or it's because the problem is some thing you guys have no clue about??

Posted (edited)

I keep wondering. Isn't that script a bit hard to understand/read and write?

I've tried to recreate it a bit with what I thought you wanted. I think this one is much clearer. (and easier)

My guess is that you script is somewhere stuck in a loop figuring out the time or something. That is my only explanation.

Else some other process may cling with you script.

(It's an untried script cause of the time limitations)

#include <Date.au3>
Dim $difference

If @WDAY < 2 Or @WDAY > 6 Exit                      ; Exit script if weekdays are before monday or after friday
If @HOUR >= 16 Or <= 8 Then Exit                    ; Exit script if the hour is after 16 or before 8

Do                                                  ; Go into the do until loop between monday and friday
    If @WDAY = 6 Then                               ; if day of the week is friday set stoptime to 12:00. Else set stoptime to 16:30
        $hour = 12
        $minute = 0
    Else
        $hour = 16
        $minute = 30
    EndIf
    Do
        Sleep(30000)                                ; Check every 30 seconds
    Until @MIN >= 29 Or @Min <= 31                  ; Until the minutes of the clock are between 29 and 31. Then below the script runs every 30 mins around full and half clock.
    Do
        modifylist()                                ; Goto the function you want
        sleep(1799990)                              ; Sleep for almost 30 minutes. Took a little less for the script to run.
    Until @HOUR = $hour And @MIN >= $minute         ; Do this until the time is after the variables $hour and $minute
    $difference = _DateDiff( 's', _NowCalc(), @YEAR & "/" & @MON & "/" & @MDAY + 1 & " 08:00:00") ; Calculate the difference between now and next day 08:00 in seconds
    $difference = $difference / 1000                ; Turn the second into milliseconds
    Sleep($difference)                              ; Sleep for the duration of the night
Until @WDAY < 2 And @WDAY > 6                       ; 2 Is monday and 6 is friday so of the day of the week is something else then inbetween, go outta the loop.
Exit ; Exit the script after the do until loop

Edit: Added the useless, but cleaner Exit at the bottom.

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Posted

Some comments in the script would be nice.

I would go for these lines as they might create a CPU consuming loop, but I don't know.

If _TimeToTicks() >= _TimeToTicks("08","00","00") And _TimeToTicks() <= _TimeToTicks("16","30","00") Then
                ExitLoop
            EndIf
Posted

Ok thxs for your help guys. I'll try your solutions and I'll repost my code with a bit more explaination so this way you can see a bit more clearly in my code and maybe poit me in another direction.

But basically what my script is doing is this:

I need the script to run like a service would but here is the limitation and conditions, I need my script to run every 30 minutes in between 8h00 am and 16h30 monday to Thrusday, Friday it runs every 30 minutes from 8h30 to noon. Once the script is done doing his job I need him to sleep until the next 30 minutes comes up. So basically it runs once at 8h00, once at 8h30 and the next time would be 9h00 and so on!

Hope this clears a bit of questions!

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
  • Recently Browsing   0 members

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