Jump to content
Sign in to follow this  
laffo16

InetGet Multi Thread Download

Recommended Posts

laffo16

its only a drafty version, so you may come accross several bugs / limitations etc, but all that out the way, it sort of works :D

; example code
If $CmdLine[0] = 0 Then
    Global $example[4]
    $example[1] = "http://www.youtube.com"
    $example[2] = "http://www.yahoo.com"
    $example[3] = "http://www.msn.com"
    _InetGet_MultiThread($example, 3)
EndIf

; file "InetGetMultiThread.au3" code starts here
; requires
#include <File.au3>
#include <INet.au3>

If $CmdLine[0] >= 1 Then
    If $CmdLine[1] = "MultiThread" Then
        $filename = StringTrimLeft($CmdLine[3], StringInStr($CmdLine[3], "/", 0, -1))
        If StringRight($filename, 4) <> "html" And StringRight($filename, 4) <> ".htm" And StringRight($filename, 4) <> ".php" Then
            $filename &= ".html"
        EndIf
        InetGet($CmdLine[3], $filename, 1, 0)
        IniWrite(@ScriptDir & "\MultiThread.ini", "Section", "Thread" & $CmdLine[2], "0")
        Exit
    EndIf
EndIf

; function (array [containing urls], number [of threads to use])
; array element [0] is ignored
Func _InetGet_MultiThread(ByRef $inGMT_arr, $inGMT_threads)
    Global $Thread_Control[$inGMT_threads+1]
    Dim $inGMT_arr_UB = UBound($inGMT_arr)
    Dim $inGMT_Progress = 0
    If FileExists(@ScriptDir & "\MultiThread.ini") = 0 Then
        $InGMT_i = 1
        For $InGMT_i = 1 To $inGMT_threads
            IniWrite(@ScriptDir & "\MultiThread.ini", "Section", "Thread" & $InGMT_i, "0")
        Next
    EndIf
    While 1
        $InGMT_i = 1
        For $InGMT_i = 1 To $inGMT_threads
            $Thread_Control[$InGMT_i] = IniRead(@ScriptDir & "\MultiThread.ini", "Section", "Thread" & $InGMT_i, "")
        Next
        If $inGMT_Progress < $inGMT_arr_UB -1 Then
            $InGMT_i = 1
            For $InGMT_i = 1 To $inGMT_threads
                If $Thread_Control[$InGMT_i] = 0 Then
                    $inGMT_Progress += 1
                    ShellExecute(@ScriptName, "MultiThread" & " " & $InGMT_i & " " & $inGMT_arr[$inGMT_Progress], "", "Run")
                    IniWrite(@ScriptDir & "\MultiThread.ini", "Section", "Thread" & $InGMT_i, "1")
                EndIf
                If $inGMT_Progress = $inGMT_arr_UB -1 Then
                    ExitLoop
                EndIf
            Next
        Else
            $finished = 0
            $InGMT_i = 1
            For $InGMT_i = 1 To $inGMT_threads
                $finished += $Thread_Control[$InGMT_i]
            Next
            If $finished = 0 Then
                ExitLoop
            EndIf
        EndIf
    WEnd
    FileDelete(@ScriptDir & "\MultiThread.ini")
    MsgBox(0, "", "multi pass!", 1)
    Return 1
EndFunc

feel free to tamper away at ur hearts content if you feel you can improve/make a better version,

feeed me back good bad or ugly if you would

InetGetMultiThread.au3

Edited by laffo16

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.