How to properly stop background while loop while closing app designer UI
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
WENCHIN LIU
el 10 de Feb. de 2021
Editada: WENCHIN LIU
el 10 de Feb. de 2021
Hi all,
I had designed an app designer UI with a background while loop. Currently, I faced difficultyies in break the background while loop when I tried to close the UI. I use a closedRequestFunc and delete(app) operator to close the UI. However, some error just popped up after close as below:
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Invalid or deleted object.
Error in MEMS_comm_int_V4_3_backgroud_timer_running/Background (line 612)
app.outputEditField.Value = fetchOutputs(result);
Error in MEMS_comm_int_V4_3_backgroud_timer_running/SimStartStopButton_callback (line 973)
Background(app);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
Error while evaluating DestroyedObject PrivateValueChangedFcn.
Error while evaluating TimerFcn for timer 'timer-60'
Invalid or deleted object.
------------------------------------------------------------------------------------------------------------------------------------------------------------------
It seems that even the app is closed the while loop is still working and here is my understanding: In closeRequestFunc, I reseted a flag making while statement to be false but, it looked like that, after closeRequestFunc, the program would return to the stop point before closeRequestFunc and finish its works in the last while loop.
Does anyone face this problem before and know how to solve it?
0 comentarios
Respuesta aceptada
Walter Roberson
el 10 de Feb. de 2021
The background loop only gives up control at some locations, such as when it does drawnow() or pause() or uiwait() or waitfor(). Hypothetically, those are the only points at which the deletion of the objects can be processed. So between any of those and the next time you need the graphics object, use isgraphics() to test whether the object still exists.
(I said hypothetically, but I would need to look more closely into exactly what happens if a timer() or device callback such as ByteReceivedFcn deletes an object, as those callbacks can execute at the beginning of any MATLAB line.)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Code Execution en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!