FreeFry Posted November 16, 2006 Posted November 16, 2006 (edited) Hi, I got tempted to try this out when I read the posts in this Topic.So I did some coding and I think it works quite ok.It works by creating a temporary file using _TempFile, and writing au3 code to it.Then it runs the code:$i_Pid = Run(@AutoItExe & " /AutoIt3ExecuteScript " & $s_TempFile, $s_ScriptDir, $s_State, 7)Which executes the script, and saving the PID to be able to read data from the output.Using adlib you can make a function that "listens" for the output of the data...It contains 3 functions:_MultiTask_Exec($s_Au3Code, $s_CommandLine = "", $s_ScriptDir = @ScriptDir, $s_State = @SW_SHOW) _MultiTask_Read($i_Pid); Reads output from "threads" if any, otherwise sets @error to 1 and returns -1 _AdlibCheckThreads(); This functions is called by the AdlibEnable() command to do the processing of any data output from the "threads"Ok, that's about it... I'm not really sure if this would work in ALL situations, but I think so.I just wrapped this up to test if it was possible so I have not been able to thoroughly test it..Anyways, here's the code(contains a simple test to demonstrate it.. lol):expandcollapse popup#include <File.au3> #include <Array.au3> Dim $MsgBoxCode = 'Opt("TrayIconHide", 1)' & @CRLF & 'ConsoleWrite(MsgBox(4, "Question", "Is simulating MultiThreading a working Solution?"))' & @CRLF & 'FileDelete(@ScriptFullPath)' Dim $Remove = False Do For $i = 1 To 3 _MultiTask_Exec($MsgBoxCode) Next AdlibEnable("_AdlibCheckThreads") Sleep(4000) Until $SMT_GlobalArray[0] < 1 Func _AdlibCheckThreads() Local $ReturnVal If $SMT_GlobalArray[0] > 0 Then For $i = 1 To $SMT_GlobalArray[0] $ReturnVal = _MultiTask_Read($SMT_GlobalArray[$i]) If Not @error Then TrayTip("Answer", "Got answer " & $ReturnVal & " from pid " & $SMT_GlobalArray[$i], 5) _ArrayDelete($SMT_GlobalArray, $i) $SMT_GlobalArray[0] -= 1 ExitLoop EndIf Next Else AdlibDisable() EndIf EndFunc Func _MultiTask_Exec($s_Au3Code, $s_CommandLine = "", $s_ScriptDir = @ScriptDir, $s_State = @SW_SHOW) Local $i_Pid Local $s_TempFile = _TempFile(@TempDir, "au3_script", ".au3") FileWrite($s_TempFile, $s_Au3Code) $i_Pid = Run(@AutoItExe & " /AutoIt3ExecuteScript " & $s_TempFile & $s_CommandLine, $s_ScriptDir, $s_State, 7) $SMT_GlobalArray[0] += 1 ReDim $SMT_GlobalArray[$SMT_GlobalArray[0]+1] $SMT_GlobalArray[$SMT_GlobalArray[0]] = $i_Pid EndFunc Func _MultiTask_Read($i_Pid) Local $s_Return Local $i_Available_Chars = StdoutRead($i_Pid, 0, True) If $i_Available_Chars > 0 Then $s_Return = StdoutRead($i_Pid) Else SetError(1); No output $s_Return = -1; No output EndIf Return $s_Return EndFuncEdit:Added: Support for commandline when executing another "thread".Edit2:This is obviously not real Threads Edited November 24, 2006 by FreeFry
FreeFry Posted November 16, 2006 Author Posted November 16, 2006 (edited) Thanks! Edited November 16, 2006 by FreeFry
jvanegmond Posted November 16, 2006 Posted November 16, 2006 Check out Coroutine. github.com/jvanegmond
MadBoy Posted November 16, 2006 Posted November 16, 2006 I haven't yet tested how it works but i will surely use it if it realy does work I'll keep the thread in my lookout list. Maybe it will even be better My little company: Evotec (PL version: Evotec)
FreeFry Posted November 17, 2006 Author Posted November 17, 2006 (edited) Added support for commandline when executing another "thread". I needed this in a test I was doing. So here it is, I've updated first post. I was testing how simulating multi-threading would work in an aimbot ... Maybe one should run 4 "threads" scanning 4 squares around the mouse, and reporting found coords back to the main app.. hmm I wonder if it would have a positive impact on performance using multiple scanners instead of just running one pixelsearch over the area .. hmm Edited November 17, 2006 by FreeFry
piccaso Posted November 18, 2006 Posted November 18, 2006 it Hurts me when you call a process thread are you guys realy willing to sacrifice Scite's Syntax highlighting just for creating another process...this is no offence but you dont have to reinvent the wheel.you could pick up Coroutine or that CoProc stuff i did some time ago and make is better. CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
FreeFry Posted November 24, 2006 Author Posted November 24, 2006 As I thought I made clear in the first post by using "" when I used the word thread, and as this whole topic states: It's simulated "MultiThreading", meaning it runs another process that executes a bit of code, it's not a real Thread. As this is rather advanced, one would have to make sure not to make errors when writing the other "thread(s)" code, therefore I don't really think the scite syntax highlightning is much of a sacrifice. And I glanced at the CoRoutine UDF but I thought it was a little... complicated to implement. As for your CoProc thing I didn't know existed at this time, neither would that that stopped me from posting this. And as the first post states, I got tempted to try it out myself, as I like to challenge my own skills to do something instead of just only relying on others. First post updated to clarify the obvious.
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