Listening an event when another function of the class is running?
Mostra commenti meno recenti
Hello,
My class looks like:
classdef linescan99 < handle
methods
function obj = linescan99(obj_surveilleur_de_contact)
addlistener(obj_surveilleur_de_contact,'Contact',@obj.handleEvnt);
end
function follower(obj)
while 1
%computations
end
end
end
end
I've noted that when the follower function is executing, the class is unable to listen a possible event 'Contact'. What's unfortunate: this event would lead to a break of the follower function while 1 loop...
Do you know how to force the function to listen the event? maybe inside the loop?
Thank you very much
Risposta accettata
Più risposte (2)
Geoff Hayes
il 17 Mar 2016
Michaël - without seeing more of your code, in particular the handleEvent or all of follower, it is difficult to know for sure what is going wrong. But if I were to guess, it may be because of your while loop
while 1
% computations
end
Is this a "tight" while loop that does not allow itself to be interrupted? Are there any calls to drawnow or pause? If not, then this could mean that the while loop will continue to run and monopolize all the processing thus not "giving a chance" to any other call until it has been completed. If I ever write something similar, then I put a short pause in the code to temporarily halt execution and allow other events (callbacks etc.) to occur.
while 1
% computations
% pause for fraction of a second
pause(0.01);
end
Try the above and see what happens!
5 Commenti
Walter Roberson
il 17 Mar 2016
The documentation implies in various places that timer interrupts can occur between any two lines, but that all other interrupts can only occur when you encounter a drawnow() or pause() or waitfor() or uiwait() or figure() or reach the command line.
Michaël
il 17 Mar 2016
Geoff Hayes
il 17 Mar 2016
...the while 1 of my first class doesn't seem to be executed during this pause
Isn't the pause in the while loop? Can you post the code (i.e. attach) so that we can see the changes?
Michaël
il 17 Mar 2016
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!