ZeroClock Posted May 21, 2016 Share Posted May 21, 2016 expandcollapse popup#include <Array.au3> Opt("MustDeclareVars", 1) Func Test_1($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-1", "Added Thread #1" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start Func Test_2($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-2", "Added Thread #2" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start Func Test_3($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-3", "Added Thread #3" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start Local $Ax[4] = [100, 'A', 200, 'B'] Local $N = 10 Local $Bx[4] = [300, 'C', 400, 'D'] _Sub_Thread_CallBack_Func("Test_1", $Ax) _Sub_Thread_CallBack_Func("Test_2", $N) _Sub_Thread_CallBack_Func("Test_3", $Bx) MsgBox(0x40, "Thread-0", "## Default_Thread ##") ;################################################################################################################################################# Func _Sub_Thread_CallBack_Func($F, ByRef $P) Local $Px = "", $L = StringLen($P) If IsArray($P) Then For $i = 0 To (UBound($P)-1) Step 1 $Px &= $P[$i] &"," Next $Px = StringLeft($Px, (StringLen($Px) -1) ) $L = StringLen($Px) $P = $Px EndIf Local $H = DllCallbackRegister($F, "int", "DWORD_PTR") Local $S = DllStructCreate("INT; Char["& $L &"]") DllStructSetData($S, 2, $P) DllStructSetData($S, 1, $L) Local $R = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, _ "long", DllCallbackGetPtr($H), "ptr", DllStructGetPtr($S), "long", 0, "int*", 0) ;DllCallbackFree($H) ;Return $R Sleep(10) EndFunc Func _STCBF_Struct(ByRef $x) Local $y = DllStructGetData(DllStructCreate("INT; Char["& DllStructGetData(DllStructCreate("INT; Char[1]", $x), 1) &"]", $x), 2) Local $Ar = StringSplit($y, ',', 2) Return $Ar EndFunc ;################################################################################################################################################# creates a thread and already passes the data in a array. boludoz and angrof 2 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 22, 2016 Moderators Share Posted May 22, 2016 ZeroClock As the AutoIt developers have always stated that AutoIt is not thread safe, I would like to point out that readers use this code at their own risk and should not expect any official support. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
junkew Posted May 22, 2016 Share Posted May 22, 2016 Not working under windows 10 64 bits. I assume byte/stackalignment issues. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ZeroClock Posted May 22, 2016 Author Share Posted May 22, 2016 junkew I use win 10 x64 . run the script in x86 ? Link to comment Share on other sites More sharing options...
ZeroClock Posted May 22, 2016 Author Share Posted May 22, 2016 Melba23 you could apply a traffic light ? it would be possible ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 22, 2016 Moderators Share Posted May 22, 2016 ZeroClock, Quote you could apply a traffic light ? it would be possible ? What do you mean? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ZeroClock Posted May 22, 2016 Author Share Posted May 22, 2016 7 minutes ago, ZeroClock said: Melba23 you could apply a traffic light ? it would be possible ? 5 minutes ago, Melba23 said: ZeroClock, What do you mean? M23 if you use a mutex approach , become thread-safe ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 22, 2016 Moderators Share Posted May 22, 2016 ZeroClock, All I know is what I posted above. The Devs have always said that AutoIt is not thread safe so I doubt there is any easy fix or they would have introduced it given the number of times this subject comes up. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ZeroClock Posted May 22, 2016 Author Share Posted May 22, 2016 16 minutes ago, Melba23 said: ZeroClock, Tutto quello che so è quello che ho postato sopra. Gli sviluppatori hanno sempre detto che AutoIt non è thread-safe quindi dubito ci sia alcuna soluzione facile o che avrebbe introdotto è dato il numero di volte in cui questo argomento viene in su. M23 OK thanks Link to comment Share on other sites More sharing options...
ZeroClock Posted May 22, 2016 Author Share Posted May 22, 2016 1 hour ago, junkew said: Not working under windows 10 64 bits. I assume byte/stackalignment issues. Local $R = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, _ "LONG_PTR", DllCallbackGetPtr($H), "LONG_PTR", DllStructGetPtr($S), "long", 0, "int*", 0) change this code in the script Link to comment Share on other sites More sharing options...
junkew Posted May 22, 2016 Share Posted May 22, 2016 expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> Opt("MustDeclareVars", 1) Local $Ax[4] = [100, 'A', 200, 'B'] Local $N = 10 Local $Bx[4] = [300, 'C', 400, 'D'] ;~ MsgBox(0x40, "Thread-0", "## Default_Thread ##") ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") Local $btnOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) _Sub_Thread_CallBack_Func("Test_1", $Ax) _Sub_Thread_CallBack_Func("Test_2", $N) _Sub_Thread_CallBack_Func("Test_3", $Bx) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $btnOK ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) Func Test_1($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-1", "Added Thread #1" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start Func Test_2($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-2", "Added Thread #2" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start Func Test_3($x) Local $Array = _STCBF_Struct($x) Local $At = '' For $i = 0 To (UBound($Array)-1) Step 1 $At &= $Array[$i] &' - ' ;ConsoleWrite("$Array["& $i &"] = "& $Array[$i] &@CRLF ) Next MsgBox(0x40, "Thread-3", "Added Thread #3" &@CRLF&@CRLF& StringLeft($At,(StringLen($At) -3)) ) EndFunc ;==> _Thread_Start ;################################################################################################################################################# Func _Sub_Thread_CallBack_Func($F, ByRef $P) Local $Px = "", $L = StringLen($P) If IsArray($P) Then For $i = 0 To (UBound($P)-1) Step 1 $Px &= $P[$i] &"," Next $Px = StringLeft($Px, (StringLen($Px) -1) ) $L = StringLen($Px) $P = $Px EndIf Local $H = DllCallbackRegister($F, "int", "DWORD_PTR") Local $S = DllStructCreate("INT; Char["& $L &"]") DllStructSetData($S, 2, $P) DllStructSetData($S, 1, $L) ;~ Local $R = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, _ ;~ "long", DllCallbackGetPtr($H), "ptr", DllStructGetPtr($S), "long", 0, "int*", 0) Local $R = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, _ "LONG_PTR", DllCallbackGetPtr($H), "LONG_PTR", DllStructGetPtr($S), "long", 0, "int*", 0) ;DllCallbackFree($H) ;Return $R Sleep(10) EndFunc Func _STCBF_Struct(ByRef $x) Local $y = DllStructGetData(DllStructCreate("INT; Char["& DllStructGetData(DllStructCreate("INT; Char[1]", $x), 1) &"]", $x), 2) Local $Ar = StringSplit($y, ',', 2) Return $Ar EndFunc ;################################################################################################################################################# Above W10, 64 bits but directly shows problems when GUI is "stolen" from mainthread FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
junkew Posted May 22, 2016 Share Posted May 22, 2016 BTW I created FAQ so we can clearly document the Multithreading that every n months seems to be popping up https://www.autoitscript.com/wiki/FAQ#Multithreading FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
iamtheky Posted May 22, 2016 Share Posted May 22, 2016 Quote multiple threads on this subject Multithreading Or "While the forum is multithreaded, AutoIt is not. Unsafe IPC is the best you will ever get, ever." ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
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