Jump to content

Recommended Posts

Posted (edited)

Ever happened to you to have blocked app? Window just stopped responding?

In AutoIt there isn't much to do when that happens. Just wait or manually kill your app.

Embarrassing for you as coder, surly ...Should be.

What about this. I register internal handler and when my app hangs next time, I deal with that the way I like it. Maybe try to unblock it or notice the behavior for the future or simply exit, whatever...

This UDF gives you ability to register function to call when app stops responding. Placeholder for the function is defined as (name is irrelevant):

Func _OnHungApp($iParam1, $iParam2) 
EndFunc

Parameters are:

  • $iParam1 - lparam DllCall type
  • $iParam2 - wparam DllCall type
So you can pass whatever you want to the function. Default is 0, 0.

Handler works differently depending on what you return from _OnHungApp(). Three possibilities:

  • In case you return $HUNGAPP_EXITHANDLER (0/False) handler will no longer be run. This is also the case if you don't specify any return value.
  • If you return $HUNGAPP_EXITPROCESS (1/True) you will exit the app with the exit code you specified when registering handler.
  • By returning $HUNGAPP_CONTINUEHANDLER (259) handler continues handling.
Unregistering and freeing resources is done by _OnHungAppUnRegister() function. It's optional. Handler is very low on requirements.

Registering is done after you create your GUI (need that handle) or if your app is GUI-less then pass something like:

WinGetHandle(AutoItWinGetTitle())

Function definition is:

_OnHungAppRegister($hWnd, $sFunction[, $iInterval = Default[, $vParam1 = Default[, $vParam2 = Default[, $iExitCode = Default]]]])

Description for parameters:

$hWnd - A handle to the window to be monitored.$sFunction - Function to call when 'not responding' state is detected.$iInterval - Optional time interval in which to repeat the tesing. Default is 1000 ms (1sec).$vParam1 - Optional parameter to pass to the function (lparam). Default is 0.$vParam2 - Optional parameter to pass to the function (wparam). Default is 0.$iExitCode - Optional exit code for the app to return. Default is 0.

Another function is _OnHungAppRegisterEx. That one works slightly different. The benefits are that you can choose time value at which _OnHungApp() will be called. This is more advanced approach since you are in complete control. That one is defined as:

_OnHungAppRegisterEx($hWnd, $sFunction[, $iHungAppTime = Default[, $vParam1 = Default[, $vParam2 = Default[, $iExitCode = Default]]]])

Parameters:

$hWnd - A handle to the window to be monitored.$sFunction - Function to call when 'not responding' state is detected.$iHungAppTime - Optional time value in ms at which window will be flagged as unresponding one. Default is 5000 ms. Minimum is 500 ms.$vParam1 - Optional parameter to pass to the function (lparam). Default is 0.$vParam2 - Optional parameter to pass to the function (wparam). Default is 0.$iExitCode - Optional exit code for the app to return. Default is 0.$iInterval - Optional time interval in which to repeat the tesing. Default is 250 ms.

Script with few examples:

OnHungApp.zip

Edited by trancexx

♡♡♡

.

eMyvnE

Posted

This is cool :blink:

One question though, if the time is set for 1000ms, then why does it take 5 seconds before _OnHungApp runs?

That's the timeout value used by Windows to flag app as not responding one.

Function checks every 1sec to determine if 5sec of non-responding state elapsed. When that happens it will check every 1sec to determine if window will start responding.

♡♡♡

.

eMyvnE

Posted

Thanks for sharing!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

I thought maybe to add one more function. It's called _OnHungAppRegisterEx().

This one allows even more control since it's not depended on IsHungAppWindow function and have additional parameter for setting time-out value when to trigger registered function.

Uber function.

♡♡♡

.

eMyvnE

  • 6 years later...
Posted

Sorry to Necro post, but will this work with "...has stopped working"? and what of using a Process handle instead of window handle?

What is what? What is what.

  • 4 weeks later...
Posted
On 24.1.2017 at 10:30 PM, Biatu said:

Sorry to Necro post, but will this work with "...has stopped working"? and what of using a Process handle instead of window handle?

I never used this function, but will consider to do so .. :D

I think it could work if you regsiter the hwnd of the Autoit-Window. Each autoit executable has a hidden Autoit-Window automatically created. You might get the handle and use this for exe-Files that have no GUI ..?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...