FaridAgl Posted November 17, 2011 Share Posted November 17, 2011 (edited) We all know AutoIt is not a MultiThreaded Language and we don't expect it to be.There is only 1 solution to simulate MultiThreading in AutoIt, using a3x files.Example:You made a tool that will check internet connection every 1 second and notify you when the connection lost. At the same time when you are checking the connection every 1 second you want to control bandwidth as well.Both of them normally need a Loop, in AutoIt it's not possible to have more than 1 Loop running at the same time, so we have to use an a3x file to run 1 of this Loops as a seprated process (Child Process).Users don't know about the Child process that is runned by the main program.With this function we are able to close all Child Processes of our program on exit:expandcollapse popupFunc _ProcessGetChildren($i_pid) ; By Smoke_N Local Const $TH32CS_SNAPPROCESS = 0x00000002 Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0) If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid) Local $tagPROCESSENTRY32 = _ DllStructCreate _ ( _ "dword dwsize;" & _ "dword cntUsage;" & _ "dword th32ProcessID;" & _ "uint th32DefaultHeapID;" & _ "dword th32ModuleID;" & _ "dword cntThreads;" & _ "dword th32ParentProcessID;" & _ "long pcPriClassBase;" & _ "dword dwFlags;" & _ "char szExeFile[260]" _ ) DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32)) Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32) Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid) Local $a_pnext, $a_children[11][2] = [[10]], $i_child_pid, $i_parent_pid, $i_add = 0 $i_child_pid = DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") If $i_child_pid <> $i_pid Then $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") If $i_parent_pid = $i_pid Then $i_add += 1 $a_children[$i_add][0] = $i_child_pid $a_children[$i_add][1] = DllStructGetData($tagPROCESSENTRY32, "szExeFile") EndIf EndIf While 1 $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop $i_child_pid = DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") If $i_child_pid <> $i_pid Then $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") If $i_parent_pid = $i_pid Then If $i_add = $a_children[0][0] Then ReDim $a_children[$a_children[0][0] + 11][2] $a_children[0][0] = $a_children[0][0] + 10 EndIf $i_add += 1 $a_children[$i_add][0] = $i_child_pid $a_children[$i_add][1] = DllStructGetData($tagPROCESSENTRY32, "szExeFile") EndIf EndIf WEnd If $i_add <> 0 Then ReDim $a_children[$i_add + 1][2] $a_children[0][0] = $i_add EndIf DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) If $i_add Then Return $a_children Return SetError(3, 0, 0) EndFunc ;==>_ProcessGetChildrenIt's good, but what if you have 5 a3x files that you want all of them at the same time? When user look at Task Manager he will see your program is running 6 times! Something like this:My Program.exe ;Main ProgramMy Program.exe ;a3x 1My Program.exe ;a3x 2My Program.exe ;a3x 3My Program.exe ;a3x 4My Program.exe ;a3x 5Terrible!What i'm looking for is some way to hide Child Processes to have:1. Really nice trick to simulate MultiThreading.2. Do our job as best as we want ( More than 1 Loop at the same time )3. All of child processes will be closed on the main Process's exit ( With above function ) .4. User will not see this:My Program.exeMy Program.exeMy Program.exeMy Program.exeMy Program.exeMy Program.exeI know it can be used for really bad things and it's exactly why i explained it in this wall of text.If it's not possible show me some ways better than hiding child processes.At the end, sorry for Misspelling. Edited November 17, 2011 by D4RKON3 http://faridaghili.ir Link to comment Share on other sites More sharing options...
Valik Posted November 17, 2011 Share Posted November 17, 2011 Why is this such a hard concept to understand? Just because you don't have bad uses for something doesn't mean any posted information won't instantly be used to make bad things. It's not the intent that gets threads like this locked, it's the knowledge itself. Thread locked for what should be an incredibly obvious reason. Link to comment Share on other sites More sharing options...
Recommended Posts