Sign in to follow this  
Followers 0
ProgAndy

Multi Threading in AutoIT

9 posts in this topic

#1 ·  Posted (edited)

Hi!

Just now I checked something out and found out that it is possible to do multithreading with AutoIT:

$handle = DllCallbackRegister("_Threadstart","int","ptr")

; Struct to send to the Thread
$dll = DllStructCreate("Char[200];int")
DllStructSetData($dll,1,"hi")
DllStructSetData($dll,2,1234)

;Call the Thrread
$ret = DllCall("kernel32.dll","hwnd","CreateThread","ptr",0,"dword",0,"long",DllCallbackGetPtr($handle),"ptr",DllStructGetPtr($dll),"long",0,"int*",0)

MsgBox(0, "Thread-Info", "Handle: " & $ret[0] & @CRLF & "Thread-ID: " & $ret[6])

Func _ThreadStart($x)
    For $i = 1 To 10
        ConsoleWrite("Thread 1 !!!"&@LF)
        Sleep(100)
    Next
    
    $y = DllStructCreate("char[200];int",$x)
    MsgBox(0, "Thread 1", DllStructGetData($y,1) & @CRLF & DllStructGetData($y,2)&@CRLF &"AutoIt can Multithreading !!!")
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ok, it can do two things, but when a thread is called, is the main script paused? (like AdLibEnable)

else: well done.

maybe you can make it more user-friendly.

Edit: What about _ThreadStop ?

Edited by kip

Share this post


Link to post
Share on other sites

"AutoIt can Multithreading !!!"

Nope.

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

alright, here's a question.

Why does the msgbox with the threadhandle only pop-ups once?

$ret = DllCall("kernel32.dll","hwnd","CreateThread","ptr",0,"dword",0,"long",DllCallbackGetPtr($handle),"ptr",DllStructGetPtr($dll),"long",0,"int*",0)

While 1
    MsgBox(0, "Thread-Info", "Handle: " & $ret[0] & @CRLF & "Thread-ID: " & $ret[6])
WEnd

Func OnAutoItExit()
    Exit
EndFunc

Func _ThreadStart($x)

   
    $y = DllStructCreate("char[200];int",$x)
    While 1
        MsgBox(0, "Thread 1", DllStructGetData($y,1) & @CRLF & DllStructGetData($y,2)&@CRLF &"AutoIt can Multithreading !!!")
    WEnd
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Don't know. I haven't tested this much, but I have also the problem, that The Thread-MsgBox appears twice, after the Handle-Box is closed :)

-> I think The AutoIT-Interpreter doesn't work very well with Threads, erven when its now possible to Create them

Edit: Another problem: When one Thread Close, the whole Script exits :)

With 2 Threads I get sometimes a stack-error :party:

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

maybe a Call() replacement. :)

If you need to have a concurrent process then you can use Run or ShellExecute to run another script and communicate with it using messages. The other process can ask for the value of any global variable it needs using messages, as well as being passed parameters. Piccaso has already done a a udf for that. Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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