How to exit script gracefully Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

How to exit script gracefully

24 Mar 2018, 12:23

Hello

In my script I'm using OnExit, Quit to call my Quit subroutine which then eventually calls ExitApp.

My concern is that Quit might interrupt some other thread that was doing something important like writing a file, and interrupted it half way through, leaving those files in an inconsistent state.

How can I avoid this possibility? i.e allow all interrupted threads on the stack to finish, then ExitApp.

Thanks
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to exit script gracefully  Topic is solved

24 Mar 2018, 21:53

A critical thread will be interrupted in emergencies. Emergencies consist of: 1) the OnExit subroutine; [...]
Regardless of whether there's an OnExit subroutine, the user can generally exit the script while a critical thread is running. However, aside from forcibly terminating the process (which you just can't stop), that requires the process to be responding to messages, such as the message sent when a user right clicks the tray icon. That doesn't happen while in the middle of an I/O operation, but it could happen (for instance) in between two calls to File.Write(). Using Critical to increase the message check frequency (e.g. Critical 10000) would make it less likely.

If you override the WM_COMMAND (0x111) message when wParam is ID_FILE_EXIT (65405) or ID_TRAY_EXIT (65307), you can make the Exit Script menu options do whatever you want. However, there are still other ways to exit the script, such as Reload, starting a new instance of a #SingleInstance script, or logging off the computer.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, Joey5, supplementfacts and 132 guests