[Solved]EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Discussion related to "Everything" 1.5.
Post Reply
Herkules97
Posts: 220
Joined: Tue Oct 08, 2019 6:42 am

[Solved]EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by Herkules97 »

I have a script with AutoIt that logs window titles.
While EBV instances are exiting, it doesn't log anything. After it's done exiting, only new stuff after exit is logged.

Here's the entire script, excluding the first and last quotation marks, if you want to figure out what step it might be that causes it:
"#NoTrayIcon
#include <FileConstants.au3>

$oldWindow = "placeholder"
if not FileExists("\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin") Then
DirCreate("\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin")
EndIf

while 1
sleep(1)
$sText = WinGetTitle("[ACTIVE]")
if $oldWindow<>$sText Then
;MsgBox(1,"Change detected",$oldWindow & @CRLF & $sText)
$logfile="\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin" & "\Timestamped window titles_" & @YEAR & "-" & @MON & "-" & @MDAY & ".log"
$hFileOpen = FileOpen($logfile, $FO_APPEND)
FileWriteLine($hFileOpen, @YEAR & "-" & @MON & "-" & @MDAY & ";" & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & ";" & $sText)
$oldWindow=$sText
FileClose($hFileOpen)
EndIf
WEnd"

Would be sweet if I could exit EBV and do other stuff and it can log those other things like normal.
I haven't done much checking for other programs, but for those I've done they have not paused this logging.
The worst case is my monolith instance which might take 5 minutes to exit. So for at most 5 minutes after I discovered this, I sit and listen to music without doing much more so I can log after it's done. Alternatively I restart then go to the toilet and it'll be done when I get back.
Last edited by Herkules97 on Tue Dec 09, 2025 11:53 pm, edited 1 time in total.
void
Developer
Posts: 19870
Joined: Fri Oct 16, 2009 11:31 pm

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by void »

I suspect autoit is seeing Everything as the active window, even after the window is destroyed and Everything is exiting.
Everything doesn't process the message loop when exiting.

I guess autoit is using WM_GETTEXT to get the title from the no-longer-existing Everything window and will block until the Everything process exits.

Please add the following to the start of your script to avoid the blocking:

Code: Select all

Opt("WinWaitDelay", 0)
Herkules97
Posts: 220
Joined: Tue Oct 08, 2019 6:42 am

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by Herkules97 »

void wrote: Mon Dec 08, 2025 2:35 am I suspect autoit is seeing Everything as the active window, even after the window is destroyed and Everything is exiting.
Everything doesn't process the message loop when exiting.

I guess autoit is using WM_GETTEXT to get the title from the no-longer-existing Everything window and will block until the Everything process exits.

Please add the following to the start of your script to avoid the blocking:

Code: Select all

Opt("WinWaitDelay", 0)
Did not do it, but I could've placed it wrong.

Did you mean first in the entire document or just after the include line, or does it not matter? It's looking like this right now.
"#NoTrayIcon
#include <FileConstants.au3>


Opt("WinWaitDelay", 0)

$oldWindow = "placeholder""
void
Developer
Posts: 19870
Joined: Fri Oct 16, 2009 11:31 pm

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by void »

That is the correct location, instead of using
WinGetTitle("[ACTIVE]")


Please try using the win32 API
GetWindowText
instead:

Code: Select all

#NoTrayIcon
#include <FileConstants.au3>

Func _SafeGetWindowText($hWnd)
    Local $tLen = DllCall("user32.dll", "int", "GetWindowTextLengthW", "hwnd", $hWnd)
    If @error Or $tLen[0] = 0 Then Return ""

    Local $iLen = $tLen[0] + 1
    Local $tBuf = DllStructCreate("wchar[" & $iLen & "]")

    DllCall("user32.dll", "int", "GetWindowTextW", _
        "hwnd", $hWnd, _
        "ptr", DllStructGetPtr($tBuf), _
        "int", $iLen)

    Return DllStructGetData($tBuf, 1)
EndFunc

Func GetActiveWindowTitleNoHang()
    Local $hWndCall = DllCall("user32.dll", "hwnd", "GetForegroundWindow")
    If @error Then Return ""

    Local $hWnd = $hWndCall[0]
    If $hWnd = 0 Then Return ""

    Return _SafeGetWindowText($hWnd)
EndFunc

$oldWindow = "placeholder"
if not FileExists("\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin") Then
DirCreate("\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin")
EndIf

while 1
sleep(1)
$sText = GetActiveWindowTitleNoHang()
if $oldWindow<>$sText Then
;MsgBox(1,"Change detected",$oldWindow & @CRLF & $sText)
$logfile="\C9\Portables\AutoIt v3.3.16.1\Outputs" & "\activewin" & "\Timestamped window titles_" & @YEAR & "-" & @MON & "-" & @MDAY & ".log"
$hFileOpen = FileOpen($logfile, $FO_APPEND)
FileWriteLine($hFileOpen, @YEAR & "-" & @MON & "-" & @MDAY & ";" & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & ";" & $sText)
$oldWindow=$sText
FileClose($hFileOpen)
EndIf
WEnd
Herkules97
Posts: 220
Joined: Tue Oct 08, 2019 6:42 am

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by Herkules97 »

void wrote: Tue Dec 09, 2025 12:40 am That is the correct location, instead of using
WinGetTitle("[ACTIVE]")


Please try using the win32 API
GetWindowText
instead
I can confirm that your code made it work and at all points when exiting the largest instance it was still recording all of it. Did you happen to know what to change from building EBV? Or did you have to read documentation for AutoIt or/and Windows?

Also should I start changing the titles of the posts, like "(Solved) EBV freezes window title monitoring from AutoIt when it's in the process of exiting"? No one seems to do it, curious if that screws with something. I am thinking of doing it to any threads I've posted that were solved. Maybe change the unsolved to say that in the title too?
void
Developer
Posts: 19870
Joined: Fri Oct 16, 2009 11:31 pm

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by void »

It's how Windows messaging works.
If you don't process the message queue, other applications will hang when trying to communicate.

WinGetTitle will block until the external program processes the message queue.

GetWindowText uses a cached title for top level windows and doesn't have this blocking issue.

WinGetTitle can get text from any window, including control windows, like an edit box.
GetWindowText only works for top level windows in other programs
-So there's limitations with GetWindowText, but it's fine for your use case.

GetWindowText API.


Also should I start changing the titles of the posts, like "(Solved) EBV freezes window title monitoring from AutoIt when it's in the process of exiting"?
Please changed to [solved]
But I'm not going to enforce this.
Herkules97
Posts: 220
Joined: Tue Oct 08, 2019 6:42 am

Re: EBV freezes window title monitoring from AutoIt when it's in the process of exiting

Post by Herkules97 »

void wrote: Tue Dec 09, 2025 9:26 pm Please changed to [solved]
But I'm not going to enforce this.
Done.

Also I'm running both in case they differ. I don't imagine there is much of a loss.
I did notice your method not only doesn't get paused but might be much faster. In the realm of milliseconds..Sometimes 50-70ms faster from the little I compared.
So much faster that apparently Windows Notepad opens an empty document window if you directly open a document with it.
So for example opening the log itself, the last entry seems to always be an unnamed window title from Windows Notepad.
Post Reply