# Thread

Sets the priority or interruptibility of threads. It can also temporarily disable all timers.

Thread, NoTimers [, false]
Thread, Priority, n
Thread, Interrupt [, Duration, LineCount]

Thread, NoTimers [, false]: Prevents interruptions from any timers until the current thread either ends, executes "Thread, NoTimers, false", or is interrupted by another thread that allows timers (in which case timers can interrupt the interrupting thread until it finishes).

If "Thread NoTimers" is not used in the auto-execute section (top part of the script), all threads start off as interruptible by timers (though the settings of "Thread Interrupt" [below] will still apply). By contrast, if the auto-execute section turns on NoTimers but never turns it off, every newly launched thread (such as a hotkey, custom menu item, or timer) starts off immune to interruptions by timers.

Regardless of the default setting, timers will always operate when the script has no threads (unless Pause has been turned on).

"Thread, NoTimers" is equivalent to "Thread, NoTimers, true". In addition, since the true/false parameter is an expression, true resolves to 1, and false to 0.

Thread, Priority, n: Specify for n an integer between -2147483648 and 2147483647 (or an expression) to indicate the current thread's new priority. This has no effect on other threads. See Threads for details.

Due to its ability to buffer events, the command "Critical" is generally superior to "Thread Priority".

On a related note, the OS's priority level for the entire script can be changed as in this example: Process, Priority,, High

Thread, Interrupt [, Duration, LineCount]: This command should be used sparingly because most scripts perform more consistently with settings close to the defaults.

By default, every newly launched thread is uninterruptible for a Duration of 15 milliseconds or a LineCount of 1000 script lines, whichever comes first. This gives the thread a chance to finish rather than being immediately interrupted by another thread that is waiting to launch (such as a buffered hotkey or a series of timed subroutines that are all due to be run).

If either component is 0, each newly launched thread is immediately interruptible. If either component is -1, the thread cannot be interrupted as a result of that component. The maximum for both components is 2147483647.

The Interrupt setting is global, meaning that all subsequent threads will obey it, even if the setting is changed somewhere other than the auto-execute section. However, interrupted threads are unaffected because their period of uninterrutibility has already expired. Similarly, the current thread is unaffected except if it is uninterruptible at the time the LineCount component is changed, in which case the new LineCount will be in effect for it.

If a hotkey is pressed or a custom menu item is selected while the current thread is uninterruptible, that event will be buffered. In other words, it will launch when the current thread finishes or becomes interruptible, whichever comes first. The exception to this is when the current thread becomes interruptible before it finishes, and it is of higher priority than the buffered event; in this case the buffered event is unbuffered and discarded.

Regardless of this setting, a thread will become interruptible the moment it displays a MsgBox, InputBox, FileSelectFile, or FileSelectFolder dialog.

Either parameter can be left blank to avoid changing it.

#### Remarks

Due to its greater flexibilty and its ability to buffer events, the command "Critical" is generally more useful than "Thread Interrupt" and "Thread Priority".

#### Related

Critical, Threads, Hotkey, Menu, SetTimer, Process

#### Example

    Thread, priority, 1 ; Make priority of current thread slightly above average.
    Thread, interrupt, 0  ; Make each newly launched thread immediately interruptible:
    Thread, interrupt, 50, 2000  ; Make each thread interruptible after 50ms or 2000 lines, whichever comes first.