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

조회 수: 2 (최근 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 CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by