Jump to content
Sign in to follow this  
Innovative

Double looping ?

Recommended Posts

Innovative

Can i perform 2 loops together ?

Because i have a function and i want to call BOTH functions together..

But both function have a

While 1

; content

Wend

That means if i

Call("function1")

Call("function2")

only function 1 will works

if i

Call("function2")

Call("function1")

only function 2 will works

So how can i solve this problem ?

Share this post


Link to post
Share on other sites
Innovative

BUMP . Everytime i post a question about loops there is no reply . Is it that hard ?

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
PsaltyDS

Can i perform 2 loops together ?

Because i have a function and i want to call BOTH functions together..

So how can i solve this problem ?

Put both actions in a single loop, with execution controlled by flags:

Global $fFunc1 = False, $fFunc2 = False

; ...

While 1
    If $fFunc1 Then _Func1()
    If $fFunc2 Then _Func2()
WEnd

Of course the functions _Func1() and _Func2() must not contain "traps" that will prevent execution from returning to the main loop. The status of the flags can be changed by interrupting events, like a GUI in GuiOnEventMode, an AdLibEnable() function, or other logic included in the main loop itself.

:)


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

Share this post


Link to post
Share on other sites
Innovative

Prevention ? If func1 contain a loop too , does that count ?

Share this post


Link to post
Share on other sites
Richard Robertson

No, you aren't reading the response. Perform the actions that both functions perform in one loop.

Instead of

func1()
func2()

Func func1()
    While 1
         MsgBox(0, "2", "2")
    WEnd
EndFunc

Func func2()
    While 1
         MsgBox(0, "2", "2")
    WEnd
EndFuncoÝ÷ Ù:òjëh×6While 1
    MsgBox(0, "1", "1")
    MsgBox(0, "2", "2")
WEnd

For a very basic example.

Share this post


Link to post
Share on other sites
Innovative

Ok this is the function.. I've matched func1 and func2 together into that .. But only the first func that i matched worked.. The second one did not.. Please help

Func _detect2000()
    
    Local $xx = 0,$bIN = 0,$pbIN = 0, $bOUT = 0, $pbOUT = 0, $ts = 0, $pts = 0
    
    Local $frq = 0, $rateIN = 0, $rateOUT = 0, $coFAX = 0, $step = 1, $ostep = 1
    If $step = 1 Then
                    $gr1 = GUICtrlCreateGraphic(10,105,200,40,$SS_BLACKFRAME)
                    GUICtrlSetGraphic(-1,$GUI_GR_PENSIZE,1.25)
                    GUICtrlSetGraphic(-1,$GUI_GR_COLOR,0xff0000) ;0x61c200);408000
                    GUICtrlSetGraphic($gr1,$GUI_GR_MOVE,0,49)                   
                    $gr2 = GUICtrlCreateGraphic(10,95,200,50)
                    GUICtrlSetGraphic(-1,$GUI_GR_PENSIZE,1.25)
                    GUICtrlSetGraphic(-1,$GUI_GR_COLOR,0x0055e5) ;0x61c200);408000
                    GUICtrlSetGraphic($gr2,$GUI_GR_MOVE,0,49)
                EndIf
;~              GUICtrlSetGraphic(-1,$GUI_GR_COLOR,0xff0000)
                GUICtrlSetGraphic($gr1,$GUI_GR_LINE,$step, 48 - Int(($rateIN/$coFAX)/25))
;~              GUICtrlSetGraphic($gr1,$GUI_GR_COLOR,0x0055e5)
                GUICtrlSetGraphic($gr2,$GUI_GR_LINE,$step, 48 - Int(($rateOUT/$coFAX)/25))
                GUICtrlSetGraphic($gr1,$GUI_GR_REFRESH)
                GUICtrlSetGraphic($gr2,$GUI_GR_REFRESH)
                $step += 1
                If $step = 199 Then 
                    GUICtrlDelete($gr1)
                    GUICtrlDelete($gr2)
                    $step = 1
                EndIf
    While $xx = 0
        Sleep(700) ; 250 matches Task Manager
        $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPerSec, BytesSentPerSec, Timestamp_PerfTime," _
            & "Frequency_Perftime, CurrentBandwidth FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $frq = 0 Then ; get first frequency counter then repeat
                    $frq = $objItem.Frequency_PerfTime
                    ExitLoop
                EndIf
                $bIN = $objItem.BytesReceivedPersec ; current bps value, every 1000ms
                $bOUT = $objItem.BytesSentPersec
                $frq = $objItem.Frequency_PerfTime
                $ts = $objItem.Timestamp_PerfTime
                $nMAX = $objItem.CurrentBandwidth;/1000000 ; connection speed of NIC
                If $nMAX = 1000000000 Then
                    $nMAX = "1 Gb"
                    $coFAX = 125000
                    $DLrate = "7.00"
                    $ULrate = "5.00"
                ElseIf $nMAX = 100000000 Then
                    $nMAX = "100 Mb"
                    $coFAX = 12500
                    $DLrate = "2.00"
                    $ULrate = "1.00"
                ElseIf $nMAX = 10000000 Then
                    $nMAX = "10 Mb"
                    $coFAX = 1250
                    $DLrate = "1.00"
                    $ULrate = "0.50"
                EndIf
                
                ; 1 megabit (Mb) = 1,000,000 bits or 125,000 bytes or 125 kilobytes
                $rateIN = ($bIN - $pbIN) / (($ts - $pts) / $frq)
                $rateOUT = ($bOUT - $pbOUT) / (($ts - $pts) / $frq)
                GuiCTrlSetData($connecting, "      Connected through :"& @CRLF &"      "& @computername &""& @CRLF &""& @ipaddress1 &"   |   "& @ipaddress2 &"")
                GUICtrlSetData($label1,"Incoming... " & Round(($rateIN/12500)/10,2) & "Mbps   of " & $nMAX)
                GUICtrlSetData($progressbar1,Int(($rateIN/$coFAX)/10))
                GUICtrlSetData($label2,"Outgoing... " & Round(($rateOUT/12500)/10,2) & "Mbps   of " & $nMAX)
                GUICtrlSetData($progressbar2,Int(($rateOUT/$coFAX)/10)) 
                
                If Round(($rateIN/12500)/10,2) > $DLrate Then
                    TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Download detected" )
                    $downloaddetect = MsgBox(4 + 32, "Continue?", "A possible download attempt was detected!"& @CRLF &"If the download is expected, then allow it to continue else deny it."& @CRLF &""& @CRLF &"Is the download positive? Allow it to continue ?")
                    If $downloaddetect = 7 Then
                        TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Terminating downloads.." )
                         _RunDOS("ipconfig /release ""Local Area Connection""")
                        TrayTip("Terminating..", "Please wait while we detect and terminate the download process", 8, 1)
                        While 1
                        If @ipaddress1 = "127.0.0.1" Then
                            ExitLoop
                            Else
                            MsgBox(0, "Error while terminating", "The termination fail and may be caused by the following reason(s)"& @CRLF &""& @CRLF &"- You are not connecting through Local Area Connection"& @CRLF &"- Your connection is a dial-up connection or others other than Modem (broadband) LAN connection"& @CRLF &"- DOS batch file has been disabled in the registries"& @CRLF &"- There is no connection established after upload/download is detected"& @CRLF &""& @CRLF &"SG Net-Speed will now be terminated") ;ACTION
                            Exit
                        Endif
                        Wend
                        Sleep(7000)
                        _RunDOS("ipconfig /renew")
                        
                    Else
                        TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Initialing for monitor.." )
                        GUICtrlSetData($label1,"Initializing for monitor..")
                        GUICtrlSetData($label2,"Initializing for monitor..")
                        Sleep(5000)
                        TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Successfully initialized" )
                        GUICtrlSetData($label1,"Incoming... " & Round(($rateIN/12500)/10,2) & "Mbps   of " & $nMAX)
                        GUICtrlSetData($label2,"Outgoing... " & Round(($rateOUT/12500)/10,2) & "Mbps   of " & $nMAX)
                        Endif
                        endif
                If Round(($rateOUT/12500)/10,2) > $ULrate Then
                    TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Upload detected" )
                    $uploaddetect = MsgBox(4 + 32, "Continue?", "A possible upload attempt was detected!"& @CRLF &"If the upload is expected, then allow it to continue else deny it."& @CRLF &""& @CRLF &"Is the upload positive? Allow it to continue ?")
                    If $uploaddetect = 7 Then
                        TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Terminating uploads.." )
                         _RunDOS("ipconfig /release ""Local Area Connection""")
                        TrayTip("Terminating..", "Please wait while we detect and terminate the upload process", 8, 1)
                        Sleep(7000)
                        _RunDOS("ipconfig /renew")
                        If @ipaddress1 = "127.0.0.1" Then
                            Else
                            MsgBox(0, "", "fail disconnect") ;ACTION
                            
                        Endif
                        Endif
                    Endif
                If Ping(@ipaddress1) > 400 Then
                    TraySetToolTip ( "SG Net-Speed"& @CRLF &"Connecting through : "& @computername &" | "& @ipaddress1 &"    "& @CRLF &"Status : Ping overriden 400" )
                    $terminatelag = MsgBox(4 + 16, "Stop!", "Your ping has overridden 400ms!"& @CRLF &"Net-Speed would perform abnormally in this network speed, so SGNetSpeed will need to terminated!"& @CRLF &"Continue?")
                    If $terminatelag = 6 Then
                        Exit
                    Else
                        TrayTip("Informations", "Please close some background process to relieve the lag", 15)
                        Endif
                    Endif
                
                        
                $pbIN = $bIN ; set previous IN
                $pbOUT = $bOUT ; set previous OUT
                $pts = $ts ; set previous Timestamp
                ; draw a graph for the speed history
                
                ExitLoop
                
            Next
        EndIf
        If Not $isMON Then
            $xx = 1
            GUICtrlSetData($label1,"SG Net-Speed is DISABLED...")
            GUICtrlSetData($label2,"SG Net-Speed is DISABLED...")
        EndIf
        
       
               

    ;Store current processlist "state"
    ;[x][0]: Contains process name
    ;[x][1]: Contains process id
    Global $ListOne = ProcessList()
    
    
        ;[x][0]: Contains process name
        ;[x][1]: Contains process id
        Global $ListTwo = ProcessList()

        ;Verify each process exists in original state
        For $X = 1 To $ListTwo[0][0]
            $found = False

            ;Comparing by PID
            For $Y = 1 To $ListOne[0][0]
                If $ListOne[$Y][1] = $ListTwo[$X][1] Then
                    $found = True
                    ExitLoop
                EndIf
            Next
$newprocessname = _ProcessGetName ( $ListTwo[$X][1] )
            ;If no match is found in ListOne for current process in ListTwo
            If $found = False Then
                $readifAccepted = Iniread("Settings.ini", $newprocessname, "Protect", "Error")
                If $readifAccepted = $newprocessname Then
                    
                Else
                    
                
                WinSetState(_WinGetByPid($ListTwo[$X][1]), "", @SW_DISABLE)
              $processString = "ProcessName: " & $ListTwo[$X][0] & @CRLF
                $processString &= "ProcessID: " & $ListTwo[$X][1] & @CRLF
                
                ;Retrieve process path
                $processString &= "ProcessPath: " & _GetProcessPath($ListTwo[$X][1]) & @CRLF
                
                $processString &= @CRLF & "Allow detected process to remain active?"
                TrayTip("A new process is detected!", "If this is expected, you should allow it to remain active but if you are unsure about it deny it from executing", 5, 1)
                Sleep(1000)
                $result = MsgBox(4 + 48, "ProcessDefender has detected a new process", $processString)
               
                If $result = 6 Then
                    ;This will reset the first comparison state
                    WinSetState(_WinGetByPid($ListTwo[$X][1]), "", @sw_enable)
                    IniWriteSection("Settings.ini", $newprocessname, "Protect=" & $newprocessname)
                    _FileWriteLog ( @scriptdir & "\Logs.txt", "Allowed "& $newprocessname &" from starting in future" )
                    ExitLoop 2
                Else
                    ProcessClose($ListTwo[$X][1])
                    _FileWriteLog ( @scriptdir & "\Logs.txt", "Disallowed "& $newprocessname &" from starting this time" )
                    ExitLoop
                EndIf

            EndIf
            endif
        Next

        ;Check every second
        Sleep(1000)
    

Wend    
EndFunc

Share this post


Link to post
Share on other sites
PsaltyDS

Ok this is the function.. I've matched func1 and func2 together into that .. But only the first func that i matched worked.. The second one did not.. Please help

Networking operations can be slow to return (they "block" your script), waiting for I/O completion or a timeout. There's no way for me to see where the "first func" ends and the "second one" starts in that, or what it means that the second one did not work.

The While/WEnd loop you have inside _detect2000() contains all the functionality of the two things you need done at approximately the same time? So, in a generalized, high-level sense, what are these two functions that need to be performed? At what point does one or the other get hung up?

:)


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

Share this post


Link to post
Share on other sites
Innovative

Ok , let me explain.. The first function was taken from one of the example scripts.. It is to see the incoming and outgoing network.. The second function was made by me and it will prompt the user if to continue a new process..

So only the first function works .. But if i seperate those 2 scripts into 2 au3 files.. It will work.. But if i seperate those 2 scripts into 2 functions, it will not work and may due to the loops..

Share this post


Link to post
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
Sign in to follow this  

×