フィルターのクリア

timer not always running

2 ビュー (過去 30 日間)
Jim Hokanson
Jim Hokanson 2014 年 10 月 22 日
編集済み: per isakson 2015 年 6 月 12 日
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 件のコメント
Jim Hokanson
Jim Hokanson 2014 年 10 月 23 日
編集済み: per isakson 2015 年 6 月 12 日
Hi Geoff,
Thanks for the great questions! I'm using a different approach now and my problem has gone away, but I'm still curious as to why I see this problem.
To answer your questions. I have a process that takes a long(ish) time to run. The callback is being executed many times. I don't want to execute every callback, because this would take a potentially long time.
Alternatively, I could check if I am currently executing a callback, and ignore the calls to resize2. This is being done in some other code on the FEX, but it also means that I won't always run the latest callback. If I could drop callbacks, I'd rather drop earlier ones than later ones.
To drop earlier calls, and not later calls, I am using the timer approach. Every time the callback executes, I am essentially telling the timer (I think) - "wait a little bit longer until running"
Each "I ran too" should correspond with the last "I ran" statement - so the first "I ran too" should correspond with the 4th "I ran" statement.
Oops, I also noticed some abbreviations to the code that make all of this not-obvious. I've added some code above to make it obvious that I'm holding onto the timers between calls.
Make sense? Any insights or suggestions?
Thanks, Jim
Geoff Hayes
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 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by