DocTorCoder

question background

7 posts in this topic

#1 ·  Posted (edited)

Hi Guys.

I wrote a lot of autoit scripts in last year and I saw something very annoying.

For example when I search some words in a big file. For example in this little function who can rename variables from a .au3 file.

Func testme($m)
    Local $file = FileRead($m),$newfile = $file
    Local $arfile = 0, $i = 0, $line = 0,$variables = 0, $j = 0, $test = 0
    _FileReadToArray($m, $arfile)
    If $arfile[0] = "" Then
        Return 0
    EndIf
    For $i = 1 To $arfile[0] Step +1
        $line = StringSplit($arfile[$i], " =,()[]")
        If Not @error Then
            For $j = 1 To $line[0] Step +1
                $test = StringSplit($line[$j], "$")
                If Not @error Then
                _ReplaceStringInFile($newcopy, $line[$j], $varsign & FORMULAVARIABLES())
                EndIf
            Next
        EndIf
    Next
    Return 1
Endfunc

Func FORMULAVARIABLES()
    Local $v1 = Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(1000, 100000, 1) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(1000, 100000, 1)
    Return $v1
EndFunc

All works good but if I apply this on a big file with 20k lines for example and it took like 1 minute (too much time)

Now my question. Is any method to make jobs with autoit to run in background like a backgroundworker,without makeing the form to freeze?

If exist already a topic with this and i didnt found it then please excuse me and post a link to there. I am new here and I wasn't so patient to read all stuffs :D

 

PS: Why my name is not remain as I put it? It always changing to this default one! - " Solved"

Edited by DocTorCoder

DocTorCoder

Share this post


Link to post
Share on other sites



ChooseAnotherName,

 

Why my name is not remain as I put it?

I have sent you a PM to explain why - read it and then choose a sensible name. ;)

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

ChooseAnotherName,

 

I have sent you a PM to explain why - read it and then choose a sensible name. ;)

M23

Done with name. All are solved. But now my question about background. There is any way to put functions to work in background,without freezing my form?

I want to avoid adlibregister too


DocTorCoder

Share this post


Link to post
Share on other sites

DocTorCoder,

As AutoIt is single-threaded there is no way to do "work in the background". But you seem to be taking a very roundabout way to replace variable names in a file - why not just use StringRegExpReplace directly on the file? That will almost certainly be quicker than looping through arrays. ;)

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

#5 ·  Posted (edited)

DocTorCoder,

As AutoIt is single-threaded there is no way to do "work in the background". But you seem to be taking a very roundabout way to replace variable names in a file - why not just use StringRegExpReplace directly on the file? That will almost certainly be quicker than looping through arrays. ;)

M23

 

Quicker maybe. But for a file with over 100k lines , it will still freeze the form .

I think this can be done if I will pause the execution for a few miliseconds then again and again ....

Anyway that stuffs with words seaarching is just an example.I want to have posibility to run 2 loops in same time,on 2 core's ... And as you said is impossible with autoit :(

Edited by DocTorCoder

DocTorCoder

Share this post


Link to post
Share on other sites

DocTorCoder,

You could always run the "replace" script as a separate process using /AutoIt3ExecuteScript - look in the Help file under <Using AutoIt - Running Scripts> to see how it is done. And you could also compile the script into .a3x format to make it as small as possible. ;)

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

DocTorCoder,

You could always run the "replace" script as a separate process using /AutoIt3ExecuteScript - look in the Help file under <Using AutoIt - Running Scripts> to see how it is done. And you could also compile the script into .a3x format to make it as small as possible. ;)

M23

/AutoIt3ExecuteScript ? I will search about that ... thanks


DocTorCoder

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