Cleanup Code to run on exit

This topic seems to cover the situations you’ve described

1 Like