trancexx Posted August 9, 2010 Posted August 9, 2010 (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) EndFuncParameters are:$iParam1 - lparam DllCall type$iParam2 - wparam DllCall typeSo 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 August 13, 2010 by trancexx argumentum and mLipok 2 ♡♡♡ . eMyvnE
AdmiralAlkex Posted August 9, 2010 Posted August 9, 2010 This is cool One question though, if the time is set for 1000ms, then why does it take 5 seconds before _OnHungApp runs? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
KaFu Posted August 9, 2010 Posted August 9, 2010 Looks really good and sophisticated , goes straight to the codebox ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
trancexx Posted August 9, 2010 Author Posted August 9, 2010 This is cool 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
AdmiralAlkex Posted August 9, 2010 Posted August 9, 2010 Of course, I should have known that! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
slayerz Posted August 9, 2010 Posted August 9, 2010 Nice script, thanks a lot...huhu AUTOIT[sup] I'm lovin' it![/sup]
jaberwacky Posted August 10, 2010 Posted August 10, 2010 I can think of a few thousand of my scripts that could benefit from this! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
taietel Posted August 10, 2010 Posted August 10, 2010 THAT is a must! (for me! ) Thank you for sharing! Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
TheSaint Posted August 10, 2010 Posted August 10, 2010 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)
trancexx Posted August 13, 2010 Author Posted August 13, 2010 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
Biatu Posted January 24, 2017 Posted January 24, 2017 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.
Leo1906 Posted February 18, 2017 Posted February 18, 2017 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 .. 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 ..?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now