Critical

現在のスレッドが他のスレッドによって中断されるのを防ぐ、または中断されるのを可能にします。

Critical OnOffNumeric

パラメータ

OnOffNumeric

型:文字列または整数

If blank or omitted, it defaults to On. それ以外の場合は、以下のいずれかを指定します。

On: The current thread is made critical, meaning that it cannot be interrupted by another thread.

Off: The current thread immediately becomes interruptible, regardless of the settings of Thread Interrupt. 詳しくはクリティカルオフをご覧ください。

(Numeric): Specify a positive number to turn on Critical but also change the number of milliseconds between checks of the internal message queue. 詳しくは、「メッセージチェックの間隔」を参照してください。0を指定すると、Criticalがオフになります。-1 を指定すると、Critical は有効になりますが、メッセージチェックは無効になります。

戻り値

型:整数

This function returns the previous setting (the value A_IsCritical would return prior to calling the function); 0 if Critical is off, otherwise an integer greater than zero.

クリティカルスレッドの挙動

クリティカルなスレッドは中断されない。詳細は「スレッド」を参照。

メッセージボックスなどのダイアログが表示されると、クリティカルスレッドが割り込み可能になる。しかし、Thread Interruptとは異なり、ユーザーがダイアログを解除した後、スレッドは再びクリティカルになる。

Critical Off

バッファリングされたイベントが新しいスレッドの開始を待っているとき、Critical "Off"を使用しても、現在のスレッドが直ちに中断されることはありません。その代わり、割り込みが発生するまでに平均5ミリ秒の時間が経過することになります。This makes it more than 99.999 % likely that at least one line after Critical "Off" will execute before an interruption. Sleep-1や、まだ存在しないウィンドウのWinWaitなどのディレイによって、強制的に割り込みを即座に発生させることができます。

Critical "Off"は、クリティカルでないスレッドでも、現在のスレッドの無停止期間をキャンセルし、サイズなどのイベントをより早く、より予測的に処理することができるようにします。

Thread Settings

現在のCriticalの設定を保存・復元する方法については、A_IsCriticalを参照してください。ただし、Criticalはスレッド固有の設定なので、Criticalなスレッドが終了すると、その下にある/再開されたスレッド(もしあれば)は自動的にNoncriticalになります。そのため、スレッドを終了する直前にCritical "Off"を行う必要はありません。

If Critical is not used by the auto-execute thread, all threads start off as noncritical (though the settings of Thread Interrupt will still apply). By contrast, if the auto-execute thread turns on Critical but never turns it off, every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off critical.

Thread NoTimers is similar to Critical except that it only prevents interruptions from timers.

メッセージチェックの間隔

第1パラメータに正の数を指定すると(例:Critical 30)、Criticalがオンになりますが、内部メッセージキューのチェック間の最小ミリ秒数が変更されます。If unspecified, the default is 16 milliseconds while Critical is On, and 5 ms while Critical is Off. 間隔を広げると、メッセージ/イベントの到着が延期され、現在のスレッドが終了するまでの時間が長くなります。This reduces the possibility that certain OnMessage callbacks and GUI events will be lost due to "thread already running". ただし、SleepWinWaitなどの待機する関数は、この設定に関係なくメッセージをチェックします(回避策はDllCall("Sleep", "UInt", 500))。

この設定は、以下に影響します。

スクリプトの一時停止中や待機中のメッセージチェックの頻度には影響しません。

システムティックカウントは一般的に15.6ミリ秒の粒度を持つため、デルタ値の最小値は一般的に少なくとも15または16となる。前回のチェックからの期間が設定した間隔を超えないと、次のチェックはできません。例えば、16を設定すると、17以上の刻みの変化が必要となります。メッセージチェックは15.6ミリ秒のウィンドウの中でいつでも発生する可能性があるので、1から16の間のどの設定でも、1つのインターバル内に2つのメッセージチェックを許可することができます。

Note: Increasing the message-check interval too much may reduce the responsiveness of various events such as GUI window repainting.

Critical -1は、クリティカルをオンにするが、メッセージチェックを無効にします。これは、スリープ、ディレイ、ウェイトの実行中にプログラムがメッセージをチェックすることを妨げるものではありません。OnMessageコールバックで特定のタイプのメッセージを処理するときなど、メッセージのディスパッチが現在実行中のコードに干渉する可能性がある場合に便利です。

Thread (function), Threads, #MaxThreadsPerHotkey, #MaxThreadsBuffer, OnMessage, CallbackCreate, Hotkey, Menu object, SetTimer

ホットキーを押すと、ツールチップを3秒間表示します。Criticalのため、この間に起動した新しいスレッド(例:ホットキーをもう一度押す)は、ツールチップが消えるまで延期されます。

#space::  ; Win+Space ホットキー。
{
    Critical
    ToolTip "No new threads will launch until after this ToolTip disappears."
    Sleep 3000
    ToolTip  ;チップを切る。
    return ; ホットキー機能から戻ると、そのスレッドが終了します。再開される基礎となるスレッドは、定義上、非クリティカルなものです。
}