Sign in to follow this  
Followers 0
MariusN

Multithread Func() script...

3 posts in this topic

#1 ·  Posted (edited)

#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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

AutoIt does not/will never support multi-threading.

See >this topic and this page.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  
Followers 0