ProgAndy Posted March 29, 2008 Posted March 29, 2008 (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 March 29, 2008 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
Kip Posted March 29, 2008 Posted March 29, 2008 (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 March 29, 2008 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Siao Posted March 29, 2008 Posted March 29, 2008 "AutoIt can Multithreading !!!"Nope. "be smart, drink your wine"
Kip Posted March 29, 2008 Posted March 29, 2008 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 MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
ProgAndy Posted March 29, 2008 Author Posted March 29, 2008 (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 Edited March 29, 2008 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
Bert Posted March 30, 2008 Posted March 30, 2008 It is well documented that AutoIt won't Multi thread. Good attempt! Keep learning! The Vollatran project My blog: http://www.vollysinterestingshit.com/
Kip Posted March 30, 2008 Posted March 30, 2008 (edited) maybe a Call() replacement. Edited March 30, 2008 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
martin Posted March 30, 2008 Posted March 30, 2008 (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 March 30, 2008 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.
WeMartiansAreFriendly Posted November 12, 2008 Posted November 12, 2008 Is there any benefits to this, compared to other methods? Specifically _Timer functions, and Adlib(). Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now