Perform Quit script on Windows Shutdown,Restart, Sign-out (basically anything that maybe 'quit forces')

3 views (last 30 days)
Is there a way to perform DB delete just before Windows Shutdowns... and the user has the AppDesigner app running?
The Task is to remove a lock inserted into DB table, yet {OnCleanup() (partially tested)} or closeRequest are never called in this situation.
  • Also here [Quit Func], it says that "quit force bypasses finish.m and terminates MATLAB. Use this syntax to override the finish script if the script does not let you quit.". [Finish Script] will not work, I suppose.
  • Do you have any suggests or work around in this case?

Accepted Answer

Bereketab Gulai
Bereketab Gulai on 11 Mar 2020
Edited: Bereketab Gulai on 12 Mar 2020
The answer is that onCleanup() works perfectly on these conditions.
  • A public variable onCleanupArray on the app stores all the onCleanUp(s).
  • Since, the db instance is persistent type and other variables from the app cannot be accessed in the cleanUp, except if it is a local variable (dbNo) and is passed to the cleanup (cleanUpTasks) function can be accessed.
  • Here, the cleanUpTasks gets the persistent db value and executes to remove the insert.
app.onCleanupArray{1} = onCleanup(@()cleanUpTasks(dbNo));
For other example how it used, such as in Window Management:
function openWindow(winM, newWindow, varargin)
 % varargin{1}: must be of type "matlab.apps.AppBase"
 slot = nextSlot(winM);
 winM.subwindows{slot} = newWindow;
 
 % Technique to delete subwindow on parent deletion
 % This method came about with problems of MATLAB not executing
 % closeRequest callback in emergency/force quit 
 if ~isempty(varargin)
     parentAppObj = varargin{1};
     % onCleanupArray: must be public variable added to windows 
% making this call
     parentAppObj.onCleanupArray{end+1} = onCleanup(@()delete(winM.subwindows{slot}));
 end
end

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by