Jump to content

Running two functions at once? What must be done?


CrewXp
 Share

Recommended Posts

This may be a stupid question, but so far with my coding, I've never really needed it. But now, I'm trying to make a progress bar for $time seconds animate, while in the background have something taking place.

I'm trying to run the function progress() and then ()doscript, but I have to wait until progress finishes then it does the script. Which is useless for a progress bar.

Thanks!

Link to comment
Share on other sites

I'm not sure I get it. See this is an example of what I'm trying to do. timer() is the progress bar. renew() is what I want to be covered by the progress bar. Then after doing that, it initiates mainscript()

And I was wondering exactly how I can run two functions at once because I'ld also like to know for other scripts I make.

renew() ;Renews' the IP

timer() ;initiates timer showing countdown until the renew function is done (maybe 3 seconds?)

;Then after timer initiates, run script

mainscript() ;This is not included in this post

Func renew()

runwait(@comspec & \' /c \' & \"ipconfig /release\",\"\",@SW_HIDE)

runwait(@comspec & \' /c \' & \"ipconfig /renew\",\"\",@SW_HIDE)

EndFunc

Func timer()

$Timelimit = 3

$Timeleft = $Timelimit

Do

; if we\'ve got more then 60s & less then 120s, then it\'s only 1 whole min left + sec(s)

If $Timeleft > 60 And $Timeleft < 120 Then

; if it\'s a whole min, no sec

If Int($Timeleft/60) = $Timeleft/60 Then

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minute\", -1, -1, 1)

; if it\'s got trailing sec, *still* single whole min left

Else

; if we\'ve got single case sec

If ($Timeleft - (Int($Timeleft/60) * 60)) <= 1 Then

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minute \" & ($Timeleft - (Int($Timeleft/60) * 60)) & \" Second\", -1, -1, 1)

; or plural sec(s)

Else

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minute \" & ($Timeleft - (Int($Timeleft/60) * 60)) & \" Seconds\", -1, -1, 1)

EndIf

EndIf

; if we\'ve got more then 1 whole min

ElseIf $Timeleft > 60 Then

; checking for whole min only, no sec...

If Int($Timeleft/60) = $Timeleft/60 Then

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minutes\", -1, -1, 1)

; if we have multiple min & sec

Else

; if we\'ve got single case sec

If ($Timeleft - (Int($Timeleft/60) * 60)) <= 1 Then

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minutes \" & ($Timeleft - (Int($Timeleft/60) * 60)) & \" Second\", -1, -1, 1)

; or plural sec(s)

Else

ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft/60) & \" Minutes \" & ($Timeleft - (Int($Timeleft/60) * 60)) & \" Seconds\", -1, -1, 1)

EndIf

EndIf

; if we\'ve got less then 1 min, only sec left + we can just use the var now

Else

If $Timeleft <= 1 Then

ProgressOn(\"\", \"YbManager Loading...\", $Timeleft & \" Second\", -1, -1, 1)

Else

ProgressOn(\"\", \"YbManager Loading...\", $Timeleft & \" Seconds\", -1, -1, 1)

EndIf

EndIf

ProgressSet(($Timeleft / $Timelimit) * 100)

Sleep(1000)

$Timeleft = $Timeleft - 1

Until $Timeleft < 0

ProgressOff()

EndFunc

Link to comment
Share on other sites

Please try to use

[ code ] ; no spaces

; paste your code here

[ /code ] ; no spaces

*** even though the spacing doesn't work right now

EDIT ( looks like the spacing does work now...cool)

i am taking at look at your script right now

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

here is the idea.... you know i cant test it

$Prs = 0

renew();Renews' the IP
timer();initiates timer showing countdown until the renew function is done (maybe 3 seconds?)
;Then after timer initiates, run script
mainscript ();This is not included in this post








Func renew()
    RunWait(@ComSpec & \' /c \' & \"ipconfig /release\", \"\", @SW_HIDE)
    RunWait(@ComSpec & \' /c \' & \"ipconfig /renew\", \"\", @SW_HIDE)
EndFunc  ;==>renew

Func timer()
    $Timelimit = 3
    $Timeleft = $Timelimit
    $Prs = 1
EndFunc  ;==>timer

While 1

    If $Prs = 1 Then
    ; if we\'ve got more then 60s & less then 120s, then it\'s only 1 whole min left + sec(s)
        If $Timeleft > 60 And $Timeleft < 120 Then
        ; if it\'s a whole min, no sec
            If Int($Timeleft / 60) = $Timeleft / 60 Then
                ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minute\", -1, -1, 1)
            ; if it\'s got trailing sec, *still* single whole min left
            Else
            ; if we\'ve got single case sec
                If ($Timeleft - (Int($Timeleft / 60) * 60)) <= 1 Then
                    ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minute \" & ($Timeleft - (Int($Timeleft / 60) * 60)) & \" Second\", -1, -1, 1)
                ; or plural sec(s)
                Else
                    ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minute \" & ($Timeleft - (Int($Timeleft / 60) * 60)) & \" Seconds\", -1, -1, 1)
                EndIf
            EndIf
            
        ; if we\'ve got more then 1 whole min
        ElseIf $Timeleft > 60 Then
        ; checking for whole min only, no sec...
            If Int($Timeleft / 60) = $Timeleft / 60 Then
                ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minutes\", -1, -1, 1)
            ; if we have multiple min & sec
            Else
            ; if we\'ve got single case sec
                If ($Timeleft - (Int($Timeleft / 60) * 60)) <= 1 Then
                    ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minutes \" & ($Timeleft - (Int($Timeleft / 60) * 60)) & \" Second\", -1, -1, 1)
                ; or plural sec(s)
                Else
                    ProgressOn(\"\", \"YbManager Loading...\", Int($Timeleft / 60) & \" Minutes \" & ($Timeleft - (Int($Timeleft / 60) * 60)) & \" Seconds\", -1, -1, 1)
                EndIf
            EndIf
        ; if we\'ve got less then 1 min, only sec left + we can just use the var now
        Else
            If $Timeleft <= 1 Then
                ProgressOn(\"\", \"YbManager Loading...\", $Timeleft & \" Second\", -1, -1, 1)
            Else
                ProgressOn(\"\", \"YbManager Loading...\", $Timeleft & \" Seconds\", -1, -1, 1)
            EndIf
        EndIf
        ProgressSet(($Timeleft / $Timelimit) * 100)
        Sleep(1000)
        $Timeleft = $Timeleft - 1
        
        If $Timeleft < 0 Then
            ProgressOff()
            $Prs = 0
        EndIf
    EndIf
    
WEnd

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Try this:

Func renew()
    $TimeLimit = 4000
    $start = TimerInit()
    $pid = Run(@ComSpec & ' /c ' & "ipconfig /release", "", @SW_HIDE)
    ProgressOn( "Renew", "Renewing IP address")
    While ProcessExists( $pid )
        $current = TimerDiff($start)
        ProgressSet( $current * 100 / $TimeLimit)
        Sleep(20)
    WEnd
    $pid = Run(@ComSpec & ' /c ' & "ipconfig /renew", "", @SW_HIDE)
    While ProcessExists( $pid )
        $current = TimerDiff($start)
        ProgressSet( $current * 100 / $TimeLimit)
        Sleep(20)
    WEnd
    ProgressSet(100)
    sleep(500)
    ProgressOff()
EndFunc ;==>renew

renew()
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

awesome! Both responses work for different scenarios. But I have another question:

I'm also trying to make another after, but not a run command. I want to run this in the background, while a progress bar is above it too.

GLOBAL $loggedin = 0
GLOBAL $linesinfile = _FileCountLines("\\b86902\Settings$\userlist.ini")
For $j = 1 to $linesinfile
;this\'ll happen over every line in the file
GLOBAL $fileuser = FileReadLine("\\b86902\Settings$\userlist.ini", $j)
Next
Link to comment
Share on other sites

I've tried Valuaters method in this one, but just can't get it. And Bluebear's won't work because it isnt a run command I guess. I can't assign a pid to it.

Anything short and simple? Kind of like bluebear?

-Thx, heading to bed in 30 mins, hope to get this done soon. Thx so much

Link to comment
Share on other sites

better than all of the scripting we did for you.... you maybe should check this out in help.... i think it will do what you want.... and..

Much easier

AdlibEnable("myprocess")
;...
Exit

Func myprocess()
    If $process = something then......bla bla
      ;...
    EndIf
EndFunc

did you see my post in your other thread?? ( WarCrafter )

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

thanks! I'll look into that. And thanks bluebear too! I used both of them.

But I don't understand the AdlibEnable("myprocess") thing valuater. That does a function every so often, correct? So how could that be able to process the command code I last posted above with a progress bar?

It would just be repeating itself over and over, correct?

Link to comment
Share on other sites

the AdlibEnable("myprocess") thing valuater. That does a function every so often, correct?

Correct

So how could that be able to process the command code I last posted above with a progress bar?

It would just be repeating itself over and over, correct?

i would suggest putting the process bar inside the adlib()

that way you can do other things and every so often ( you determine) the process bar will be updated...that can work!!

8)

NEWHeader1.png

Link to comment
Share on other sites

Ah, smart. ;) heh

Is there also a way to say like

While Function Running

PROGRESS ON (example)

WEnd

That way, I can make the progress bar increase by how long it actually takes, not by a certain time?

But for this one, time will work good. Thx again

Link to comment
Share on other sites

Noo. I tried the addlib function and my progress bar stalls. It doesn't every 100 ms like it's supposed to. When it's doing a command like ReadLines or something, it stalls for 4 seconds then it keeps going again. Augh!

Link to comment
Share on other sites

I like this method. The first block is just to set up my test file.

#include <file.au3>
#Include <string.au3>

; Create the test file
Const $ForReading = 0, $ForAppending = 1, $ForWriting = 2
$myfile = @ScriptDir & "\userlist.ini"
$myfileH = FileOpen($myfile, $ForWriting)
ProgressOn("Progress", "Writing file..."); Initialize progress bar
$maxlines = 9999; Number of lines in file
$zeroes = _StringRepeat( "0", StringLen($maxlines) )
For $i = 1 to $maxlines; Write out each line.
    $num = StringLeft($zeroes, StringLen($maxlines) - StringLen($i)) & $i
    FileWriteLine( $myFileH, "user" & $num )
    ProgressSet($i/1000 * 100, "Line " & $i & " of " & $maxlines); Update the progress bar
Next
FileClose($myFileH)
ProgressSet(100)
Sleep(200)
ProgressOff()
; Finish creating test file

; ========================
; Reading back in the lines of the file
; ========================
$myfileH = FileOpen($myfile, $ForReading)
GLOBAL $loggedin = 0
GLOBAL $linesinfile = _FileCountLines($myFile)
ProgressOn("Progress", "Reading file...")
For $j = 1 to $linesinfile
;this\'ll happen over every line in the file
    GLOBAL $fileuser = FileReadLine($myfileH, $j)
    ProgressSet($j/$linesinfile * 100, "Line " & $j & " of " & $linesinfile)
Next
ProgressSet(100, " ", "Done!")
Sleep(1000)
ProgressOff()
BlueBearrOddly enough, this is what I do for fun.
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...