Jump to content
Sign in to follow this  
nekkutta

MultiThreading UDF

Does it work?  

7 members have voted

  1. 1. Does it work For you? (compiled)



Recommended Posts

nekkutta

I just created a UDF for doing Multithreading, seems to only work once the script is compiled, it's a bit messy, but I believe it should work fairly well, need some people to try it out.

The UDF:

;Multithreading Include
#include-once
Global Const $MultiThreadInt = 15684987214 ; created upon supply
Dim $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3, $MultiThreadParam4, $MultiThreadParam5, $MultiThreadParam6, $MultiThreadParam7
If $CmdLine[0] <> 0 Then
    If $CmdLine[1] = $MultiThreadInt Then
        $MultiThreadFunctionName = $CmdLine[2]
        $MultiThreadNumOfParams = $CmdLine[0] - 2
        If $MultiThreadNumOfParams = 0 Then
            Call($MultiThreadFunctionName)
            Exit
        ElseIf $MultiThreadNumOfParams > 8 Then
            MsgBox(0, "Error", "Too Many Parameters")
            Exit
        Else
            For $i = 3 To $CmdLine[0]
                Assign("MultiThreadParam" & $i - 2, StringReplace($CmdLine[$i], '"', ''))
            Next
            Switch $MultiThreadNumOfParams
                Case 1
                    Call($MultiThreadFunctionName, $MultiThreadParam1)
                    Exit
                Case 2
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2)
                    Exit
                Case 3
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3)
                    Exit
                Case 4
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3, $MultiThreadParam4)
                    Exit
                Case 5
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3, $MultiThreadParam4, $MultiThreadParam5)
                    Exit
                Case 6
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3, $MultiThreadParam4, $MultiThreadParam5, $MultiThreadParam6)
                    Exit
                Case 7
                    Call($MultiThreadFunctionName, $MultiThreadParam1, $MultiThreadParam2, $MultiThreadParam3, $MultiThreadParam4, $MultiThreadParam5, $MultiThreadParam6, $MultiThreadParam7)
                    Exit
            EndSwitch
        EndIf
    EndIf
EndIf
Func _NewThread($sFunctionName, $param1 = "", $param2 = "", $param3 = "", $param4 = "", $param5 = "", $param6 = "", $param7 = "")
    Local $NewThreadNumOfParams = 0
    For $i = 1 To 7
        If Eval("param" & $i) = "" Then ContinueLoop
        If IsHWnd(Eval("param" & $i)) Then Assign(Eval("param" & $i), String('0x' & Eval("param" & $i)))
        $NewThreadNumOfParams += 1
    Next
    If $NewThreadNumOfParams = 0 Then
        ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName , @ScriptDir, "", @SW_HIDE)
    Else
        Switch $NewThreadNumOfParams
            Case 1
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '"', @ScriptDir, "", @SW_HIDE)
            Case 2
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '"', @ScriptDir, "", @SW_HIDE)
            Case 3
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '" "' & $param3 & '"', @ScriptDir, "", @SW_HIDE)
            Case 4
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '" "' & $param3 & '" "' & $param4 & '"', @ScriptDir, "", @SW_HIDE)
            Case 5
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '" "' & $param3 & '" "' & $param4 & '" "' & $param5 & '"', @ScriptDir, "", @SW_HIDE)
            Case 6
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '" "' & $param3 & '" "' & $param4 & '" "' & $param5 & '" "' & $param6 & '"', @ScriptDir, "", @SW_HIDE)
            Case 7
                ShellExecute(@ScriptFullPath, $MultiThreadInt & ' ' & $sFunctionName & ' "' & $param1 & '" "' & $param2 & '" "' & $param3 & '" "' & $param4 & '" "' & $param5 & '" "' & $param6 & '" "' & $param7 & '"', @ScriptDir, "", @SW_HIDE)
        EndSwitch
    EndIf
EndFunc   ;==>NewThread

and a quick test script:

;multithread test
#include "Multithreading.au3"
Func One()
    MsgBox(0,'','One')
EndFunc
Func Two()
    MsgBox(0,'','Two')
EndFunc
Func Three()
    MsgBox(0,'','Three')
EndFunc
Func Four()
    MsgBox(0,'','Four')
EndFunc
Func Five()
    MsgBox(0,'','Five')
EndFunc
Func Six($sString)
    MsgBox(0,'Func Six', $sString)
EndFunc
_newthread("one")
_newthread("Two")
_newthread("Three")
_newthread("Four")
_newthread("Five")
_newthread("Six",InputBox('',''))

Let Me know what you think.

nekkutta


[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites
monoceres

This is not multi-threading. It's multi-process which is two very different things. If you do a search for it you'll find you're not the first to explore this area >_


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
nekkutta

This is not multi-threading. It's multi-process which is two very different things. If you do a search for it you'll find you're not the first to explore this area >_<

Ok, I'll grant you it isn't true multi-threading, but its probably the closest we're going to get with autoit, I tried doing a search, but I didn't really see anything that stood out from all the rest of the results junk. all I'm asking is a try out.

PS I really like your two-liner GUI :(


[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites
MrCreatoR

I am sorry, but this is the reason why it's can not work like multithreading, and thus can not be usefull:

;multithread test (failed?)
#include "Multithreading.au3"

$sVar = 1

_newthread("one")

Func One()
    MsgBox(0, $sVar, 'One')
EndFunc

$sVar is not declared in new process, it's can not be used >_<


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
SkellySoul

I am sorry, but this is the reason why it's can not work like multithreading, and thus can not be usefull:

;multithread test (failed?)
#include "Multithreading.au3"

$sVar = 1

_newthread("one")

Func One()
    MsgBox(0, $sVar, 'One')
EndFunc

$sVar is not declared in new process, it's can not be used >_<

This is why would would save all variables in a ini and let the scripts read them as it needs them.

Share this post


Link to post
Share on other sites
MrCreatoR

This is why would would save all variables in a ini and let the scripts read them as it needs them.

It's still not usefull as multithreading >_<

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
SkellySoul

It's still not usefull as multithreading >_<

I agree but was just giving some idea's

Share this post


Link to post
Share on other sites
arcker

Agree, this is not multithreading.

I'm working on the trancexx solution and this is awesome.

BTW it needs some asm and C++ knowledge.

It took me one week to understand the trancexx code so multithread is possible but you need to work hard on it,

so the interest is limited since autoit is here to simplify our life >_<


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites
nekkutta

I am sorry, but this is the reason why it's can not work like multithreading, and thus can not be usefull:

;multithread test (failed?)
#include "Multithreading.au3"

$sVar = 1

_newthread("one")

Func One()
    MsgBox(0, $sVar, 'One')
EndFunc

$sVar is not declared in new process, it's can not be used >_<

try this:

;multithread test (failed?)
#include "Multithreading.au3"

$sVar = 1

_newthread("one", $sVar)

Func One($funcVar = '')
    MsgBox(0, $funcVar, 'One')
EndFunc

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites
MrCreatoR

try this:

And what if i have hundreds of these vars? No need to answer, it's a retorical question. This is still not the same as multithreading, where you can use the same runing environment in different processes.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.