Other metod of multithreading?

01/03/2013 21:30 fuso98#1
There's some UDF or metod to make a script that support multithreading? I don't want make a loop or file comunication, i want an UDF that work very well ;) it exits?
01/03/2013 22:57 Croco™#2
Wiki:
Quote:
AutoIt is single threaded which makes asynchronous programming, concurrency and parallelism (e.g. communications applications) extremely difficult.
(This can be worked around through the use of such things as multiple processes, Component Object Model, etc., but it would be much less onerous if a multithreading API was provided for use within the language itself or its libraries.)
01/04/2013 01:29 logical691#3
As said Autoit does not support multi threading your options are:

1. Run two seperate files (something im against file one does one thing then file 2 does something every x seconds)
2. Use adlibregister - Pauses your script and does the action you want every x seconds then continues where it left off.
01/04/2013 09:56 fuso98#4
adlib register is not very good. There's a function that can execute a script in the same directory of the program without the manually execution?

sorry my bad english
01/04/2013 14:16 Lawliet#5
Code:
Shellexecute(@autoitexe, "/Autoit3ExecuteScript " & @ScriptDir & "/somescriptname.au3")
01/04/2013 18:26 lolkop#6
well threads get executed by the os like this:

Code:
execute part of thread1
execute part of thread2
...
execute part of threadN
execute part of thread1
...
thats what you can do in your script too...

Code:
While True
    <action1>
    <action2>
    [...]
    <actionN>
WEnd
for timed actions, use timer functions.

simply don't use script blocking stuff like sleeps, waits, "critical, time consuming innerloops"

to simplify this, the sum of time-consumption, of the "innerloop-actions, should stay below 0.5secs, so the user won't even notice, that there are multiple actions running in a row.
03/30/2016 23:36 Puppy609#7
; This works very very well. Low CPU. All you have is the exe in memory for each thread.

; Send messages anyway you need. Try the iniwrite()/iniread(), regwrite()/regread, or fancy _NamedPipes.

#include <WinAPI.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WinAPIShPath.au3>
#include <Misc.au3>

If $CmdLine[0] > 0 Then
If $CmdLine[1] = "MyFuncThread1" Then MyFuncThread1()
If $CmdLine[1] = "MyFuncThread2" Then MyFuncThread2()
If $CmdLine[1] = "MyFuncThread3" Then MyFuncThread3()
EndIf

If @Compiled Then
ShellExecute(@AutoItExe, "MyFuncThread1")
ShellExecute(@AutoItExe, "MyFuncThread2")
ShellExecute(@AutoItExe, "MyFuncThread3")
Else
ShellExecute(@ScriptName, "MyFuncThread1")
ShellExecute(@ScriptName, "MyFuncThread2")
ShellExecute(@ScriptName, "MyFuncThread3")
EndIf

;*** WARNING, if your thread returns without exiting - it will respawn. (Maybe you need that?)

Func MyFuncThread1()
_Singleton("MyFuncThread1", 0)
MsgBox(0, "", "Thread 1", 0)
Exit
EndFunc ;==>MyFuncThread1

Func MyFuncThread2()
_Singleton("MyFuncThread2", 0)
MsgBox(0, "", "Thread 2", 0)
Exit
EndFunc ;==>MyFuncThread2

Func MyFuncThread3()
_Singleton("MyFuncThread3", 0)
MsgBox(0, "", "Thread 3", 0)
Exit
EndFunc ;==>MyFuncThread3

[Only registered and activated users can see links. Click Here To Register...]
04/08/2016 17:59 FacePalmMan#8
Real multithreading (like stated by Puppy 609) is too instable and is doomed to crash eventually if put in a script that runs constantly. It might be useful for dllcalls that take relatively high amounts of time to be executed, and whose return value you don't need.