timer not always running
이전 댓글 표시
I have an event listener callback. In that callback I run the following code:
disp('I ran')
t = obj.timer; %obj is instance of handle class
stop(t);
set(t,'TimerFcn',@(~,~)obj.resize2(h,event_data,axes_I,count,new_xlim,new_position));
start(t)
obj.timer = t; %Hold onto new timer so that it doesn't get deleted and executes
In resize2():
disp('I ran too!')
Previously I've done: t = timer; t.StartDelay = TIMER_START_DELAY; obj.timer = t;
I'm seeing code that indicates that the callback ran, but not the resize2() function. I'm seeing something like:
I ran
I ran
I ran
I ran
I ran too
I ran
I ran
I ran too
I ran
I ran
The way the callback code is setup, I want there always to be at least one call to resize2, following any calls to the callback. Any thoughts on why I am not seeing this?
Thanks, Jim
댓글 수: 3
Geoff Hayes
2014년 10월 23일
Jim - out of curiosity, why do you start what appears to be a "single shot" timer that just calls the resize2 function? Why not replace all the timer code with just
obj.resize2(h,event_data,axes_I,count,new_xlim,new_position);
The specified execution time and the actual execution of a timer can vary because timer objects work in the MATLAB single-threaded execution environment. The length of this time lag is dependent on what other processing MATLAB is performing. To force the execution of the callback functions in the event queue, include a call to the drawnow function in your code. The drawnow function flushes the event queue.
How often is your event listener callback firing? Perhaps faster than the timer callbacks can be processed?
It would be interesting to know which "I ran" output that the "I ran too" corresponds to. (What I mean by that is, does the first "I ran too" (from above) correspond to the first "I ran" or the fourth?)
Jim Hokanson
2014년 10월 23일
편집: per isakson
2015년 6월 12일
Geoff Hayes
2014년 10월 24일
Hi Jim - That's an interesting approach which makes sense. I still wonder about the properties for your timer - how is it initialized (period, etc.)?
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!