Jump to content

Multithread Func() script...


MariusN
 Share

Recommended Posts

#RequireAdmin
#include <GUIConstantsEx.au3>

Local $Handle, $Handle1, $Handle2, $return, $struct, $Struct1, $Struct2, $x, $y, $button1, $MSG
GUICreate("multithread", 410, 360)

$button1 = GUICtrlCreateButton("Start Me Up!", 15, 90, 90, 20)

GUISetState()

While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            ExitLoop
        Case $MSG = $button1

            $Handle1 = DllCallbackRegister("ThreadTest1", "int", "ptr") ;<---calls Func ThreadTest1($x)
            $Handle2 = DllCallbackRegister("ThreadTest2", "int", "ptr") ;<---calls Func ThreadTest2($x)

            $Struct1 = DllStructCreate("Char[200];int")
            DllStructSetData($Struct1, 1, 10)
            CreateThread($Handle1, $Struct1) ;This creates thread #1

            $Struct2 = DllStructCreate("Char[200];int")
            DllStructSetData($Struct2, 1, 10)
            CreateThread($Handle2, $Struct2) ;This creates thread #2

            thirdthread() ; <---ENTER the LAST Command/Function here...
    EndSelect
WEnd

Func thirdthread()
    MsgBox(0x40, "Thread 3", "Added Thread #3")
EndFunc   ;==>FirstFunc

Func CreateThread($Handle, $struct)
    $return = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "long", DllCallbackGetPtr($Handle), "ptr", DllStructGetPtr($struct), "long", 0, "int*", 0)
    Return $return[0]
EndFunc   ;==>CreateThread

Func ThreadTest1($x)
    $y = DllStructCreate("char[255];int", $x)
    MsgBox(0x40, "Thread 1", "Added Thread #1")
EndFunc   ;==>ThreadTest1

Func ThreadTest2($x)
    $y = DllStructCreate("char[255];int", $x)
    MsgBox(0x40, "Thread 2", "Added Thread #2")
EndFunc   ;==>ThreadTest2

Found this on some site a while ago...seems quite handy. Maybe you guys can put it to good use :sorcerer:

Edited by MariusN
Link to comment
Share on other sites

if i remember well about this script, it's not multithread since each time a func is called entire script is blocked.

the only way to do MT in autoit is to use a dll with code Inside that will be executed in different thread.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
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...