Thread high priority does not work?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Thread high priority does not work?

24 Sep 2019, 13:26

Hello,
When the priority of a subroutine is set to 1, even if the priority of the GuiSize subroutine is set to a higher level, it will not be executed immediately. Why?

As in the example below, when the TEST button is pressed, the window is zoomed within 5 seconds and the edit control is not redrawn.

Code: Select all

Gui, +Resize
Gui, Add, Edit, w380 vedit
Gui, Add, Button,, TEST
Gui, Show, h200 w400
return

GuiSize:
Thread, Priority, 2
GuiControl, MoveDraw, edit, % "w" A_GuiWidth - 20
return

ButtonTEST:
Thread, Priority, 1
sleep, 5000
return
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Thread high priority does not work?

25 Sep 2019, 03:36

The GuiSize subroutine is not a thread. A thread starts, the subroutine is called, then your subroutine calls Thread, Priority, which sets the priority of the current thread. If you haven't called Thread yet, it is not relevant. If the thread cannot start because the GUI event's priority is too low, Thread will not be called.

All GUI events have a priority of 0.
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Thread high priority does not work?

25 Sep 2019, 06:44

So can the GuiSize subroutine be executed first?

My script is similar to the example above. Since I don't want to interrupt a function thread, I set its priority to 1, but this causes the implementation of the function, as shown in the above example, when the window is zoomed, GuiSize will not be executed immediately.
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Thread high priority does not work?

26 Sep 2019, 07:31

However, in the following example, when the TEST button is pressed first, and then the TEST2 button is pressed, the TEST2 thread is not executed immediately. Why?

Code: Select all

Gui, Add, Button,, TEST
Gui, Add, Button,, TEST2
Gui, Show, h200 w400
return

ButtonTEST:
Thread, Priority, 1
sleep, 5000
return

ButtonTEST2:
Thread, Priority, 2
msgbox OK
return
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Thread high priority does not work?

26 Sep 2019, 07:53

While sleeping, new threads can be launched via hotkey, custom menu item, or timer.
(https://www.autohotkey.com/docs/commands/Sleep.htm#Remarks)

If you can, try to avoid using sleep as much as possible.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Thread high priority does not work?

26 Sep 2019, 10:09

I removed Sleep, but the results were the same. TEST2 does not interrupt the TEST thread.

Code: Select all

Gui, Add, Button,, TEST
Gui, Add, Button,, TEST2
Gui, Add, ListView,, TEST
Gui, Show, h200 w400
return

ButtonTEST:
Thread, Priority, 1
i := 0
Loop, 10000
LV_Add(,++i)
return

ButtonTEST2:
Thread, Priority, 2
msgbox OK
return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Thread high priority does not work?

26 Sep 2019, 10:24

did u not see what @lexikos wrote? gui event handlers have default priority of 0.

at most u could lower(read: assign negative) the priority of (all) threads accordingly to ensure gui handlers are still at least able to interrupt them

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Peiya, ShatterCoder and 313 guests