Hi, Jimmy
I, more or less, coped with the problem. I rewrote, in some places, the logic. True, I did not find a specific reason, but users, so far, do not swear
At the same time, I found this function for monitoring hung applications
IsHungAppWindow() User32.dll