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

1 回表示 (過去 30 日間)
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?

採用された回答

Bereketab Gulai
Bereketab Gulai 2020 年 3 月 11 日
編集済み: Bereketab Gulai 2020 年 3 月 12 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by