rietproductions

autoit multithreaded?

29 posts in this topic

Is there any way to perform multithreading in autoit?

Share this post


Link to post
Share on other sites



rietproductions,

In short - No.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

rietproductions,

In short - No.

M23

Indeed short :D 

 

why not ?

Share this post


Link to post
Share on other sites

you can use multi process method!

 

 

Share this post


Link to post
Share on other sites

Multi process and multi threaded are two very things.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Func _START_BACKGROUND_FUNCTION($f)
    Local $handle = DllCallbackRegister("_SubThread", "int", "ptr")
    Local $dllstr = DllStructCreate("Char[200]")
    DllStructSetData($dllstr, 1, $f) ;arg/parameter 1
    Local $return = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "long", DllCallbackGetPtr($handle), "ptr", DllStructGetPtr($dllstr), "long", 0, "int*", 0)
    ;$return[0] - handle
    ;$return[6] - thread id
EndFunc   ;==>_START_BACKGROUND_FUNCTION
Func _SubThread($x)
    Local $get = DllStructCreate("char[200]", $x)
    Call( DllStructGetData($get, 1))
EndFunc   ;==>_SubThread

Func _TEST()
    MsgBox(0,"","Yes but there are so many problems that it is very limited.")
EndFunc

Func _TEST2()
    MsgBox(0,":)","(: :) :(")
EndFunc

_START_BACKGROUND_FUNCTION("_TEST")
_START_BACKGROUND_FUNCTION("_TEST2")

msgbox (0,0,"Can AutoIt mutlithread"); if you close main process all subtreads are closed

It is possible but there are some limitations. This runs a function in the background. I don't know what you need it for i can show you sometime how you pass values back and forth but it is somewhat advanced.

 

Edit: This example is already wrong, in some cases after it finishes the subtread it will continue to run the main thread, the only difference is if $return rertuns the data or not. You can use this Return or Not data to cancel out or continu after the function completes. Try the example a few times and you will see. It is not impossible to make it solid and stable but it is a lot of work.

Edited by Kinshima

Share this post


Link to post
Share on other sites

It's been argued many times that you can, and nothing is impossible etc...

But the fact is that AutoIt was not designed for it, and so if you can it will be very unstable and really not worth it.

If you think you absolutely 100% need it, then I suggest you turn to a language that supports it.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

@JohnOne You said it very easily. But it is not quite easy to find a language which does things just like autoit. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

His point wasn't that other languages are easier or as easy, his point was that if you REALLY need multi-threading, then don't use AutoIt because it won't work very well if at all.

Nothing AutoIt does can't be done in another language, it's just not as easy to write it in other languages.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@JohnOne You said it very easily. But it is not quite easy to find a language which does things just like autoit. 

In fairness, I'd despair if someone who can write an AutoIt script or even know what a script is, that could not find a mainstream and well supported language that can do everything AutoIt can and more, while supporting multithreading.

People are disappointed when they learn there is no support for it, but that's all it is disappointment. You can spend 6 weeks trying to multithread in AutoIt or you can spend 6 weeks learning C++ or C# etc...

2 people like this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

@JohnOne , We can do a specific thing in other languages but it is not as easy like in autoit. For eg. iniRead(). In vb.net, we can call the API function for this. But you can do the job in one line code in autoit. 

 

@BrewManNH I agree 100% with you. 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@JohnOne I know that. But why don't autoit include most of its ability to it's COM version. If so, we can glue it in our projects. I mean if i can use a UDF inside vb.net with COM, it is great help. Then this multithreading or OOP is not a problem for us.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

I'm pretty sure VB.net would be able to ShellExecute your AutoIt scripts/compiled scripts.

We know it would be great to have multithreading, but it's specifically stated that there will never be any.

Shame, but a fact, so wasting any energy at all on it is wasted time for me.

Parallel processing or another language are the only options.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@JohnOne I did that in few times. But i think it is not possible to get the data from external exes which run by shell execute. 

 

Edit - I am not arguing for multithreading. Infact i don;t know how to use multithreading. I have tested it some times. It is quite easy to start a multi threaded process, but not easy to switch between process or come back to main thread (UI thread)

 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

It probably has CreateProcess where you can read stdout or create a pipe or something. But it's still convoluted compared to languages which support threads natively.

I know you're not asking for threads, conversation is for OP benefit.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

What is the easiest language to learn after autoit that has multithreading ?

And that has eazy IDE that helps you learn like autoit scite does.

 

The only reason why i stick to autoit is because scite makes it very eazy to program etc, but i now i need to evolve.

thanks  in advance.

 

I really hope autoit will evolve into something like multithreading language some day.

Share this post


Link to post
Share on other sites

Threads are evil.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

On 18/10/2015 at 2:52 PM, Kinshima said:
Func _START_BACKGROUND_FUNCTION($f)
    Local $handle = DllCallbackRegister("_SubThread", "int", "ptr")
    Local $dllstr = DllStructCreate("Char[200]")
    DllStructSetData($dllstr, 1, $f) ;arg/parameter 1
    Local $return = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "long", DllCallbackGetPtr($handle), "ptr", DllStructGetPtr($dllstr), "long", 0, "int*", 0)
    ;$return[0] - handle
    ;$return[6] - thread id
EndFunc   ;==>_START_BACKGROUND_FUNCTION
Func _SubThread($x)
    Local $get = DllStructCreate("char[200]", $x)
    Call( DllStructGetData($get, 1))
EndFunc   ;==>_SubThread

Func _TEST()
    MsgBox(0,"","Yes but there are so many problems that it is very limited.")
EndFunc

Func _TEST2()
    MsgBox(0,":)","(: :) :(")
EndFunc

_START_BACKGROUND_FUNCTION("_TEST")
_START_BACKGROUND_FUNCTION("_TEST2")

msgbox (0,0,"Can AutoIt mutlithread"); if you close main process all subtreads are closed

It is possible but there are some limitations. This runs a function in the background. I don't know what you need it for i can show you sometime how you pass values back and forth but it is somewhat advanced.

 

Edit: This example is already wrong, in some cases after it finishes the subtread it will continue to run the main thread, the only difference is if $return rertuns the data or not. You can use this Return or Not data to cancel out or continu after the function completes. Try the example a few times and you will see. It is not impossible to make it solid and stable but it is a lot of work.

#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
;#################################################################################################################################################

 

Edited by ZeroClock

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