Page 1 of 1

Which SetBatchLines precautions ?

Posted: 20 Mar 2018, 12:33
by DigiDon
Hi everyone,

I'm currently having a hard time to see which precautions should be taken when using to maximize a script speed:

Code: Select all

SetBatchLines, -1
Indeed I'm wondering if in some cases that might not cause some crashes.

I'm using it for example in creating a GUI that display a ListView with a list of files quite similar to the ListView Main example from the documentation:
https://autohotkey.com/docs/commands/Li ... m#Examples
To maximize speed looping through the files, checking some stuff, and displaying the ListView I used "SetBatchLines, -1" at the top.
However I have sometimes crashes when launching the GUI. The script becomes unresponsive before the GUI shows up and there is nothing I can do except killing the process via task manager.
Spoiler
I saw on several occasions that it was mentioned that when using "SetBatchLines, -1" you should put manual sleeps at some places.
It was mentioned loops but I couldn't understand in which loop you should introduce the sleep.

So could someone tell me if SetBatchLines, -1 is suceptible to crash AutoHotkey with some particular commands, especially in a loop?
And if yes what should be done to prevent it while maximizing speed? Which loops can be problematic?

As sensitive commands/functions inside the script I was wondering if they can be a problem with SetBatchLines,-1 ?:
Spoiler
Thanks for your enlighment on this subject ! ;)

Re: Which SetBatchLines precautions ?

Posted: 20 Mar 2018, 14:05
by Helgef
So could someone tell me if SetBatchLines, -1 is suceptible to crash AutoHotkey with some particular commands, especially in a loop?
No, it isn't.

Setbatchlines only causes sleeps in between lines, not during any command execution. You could have timing-bugs which only appears when using setbatchlines, but setbatchlines wouldn't be the root cause.

Re: Which SetBatchLines precautions ?

Posted: 20 Mar 2018, 16:10
by wolf_II
Are you regarding "crashes" the same as "unresponsive"?
You can do something to resolve unresponsiveness caused by speeding up.
If you want to control how AHK is using its time-slice, you also should control where AHK allows OS and other programs to run.

You just make sure every Loop (For, While, Loop) contains Sleep, -1.

Re: Which SetBatchLines precautions ?

Posted: 20 Mar 2018, 19:14
by DigiDon
Thanks for answering.

Yes it becomes unresponsive and I cannot do anything but kill it via task manager. But no indeed there is no crash message.

So why should every loop contain "Sleep, -1" ?

It can be a pain to add for every loop because I have many.
It is especially difficult as the SetBatchLines take effet on the whole thread if I got it right (meaning adding sleep -1 to every loop inside the functions it is calling as well)
Shouldn't it be only in long long loops to be sure incoming messages are processed? What's the reason behind it?

Anyway in the meantime I've taken on the difficult part to re-write in a much cleaner way this part of my program to see if the issue disappear.
Could be due to something else indeed, I can't be sure.