listeners or timer, what would be recommended

7 views (last 30 days)
Dear all,
I've been working for a long time on a flexible extensive 2D/3D viewer. The viewer works great but can be slow if multiple parameters are changing simultaneously (for example cursor, level/window, zoom, viewing grid, cropbox, fusion while scrolling through a 3D image). Currently, I'm using listeners for each event, however, in some cases it executes multiple times the same functions that make the viewer a bit slow.
An alternative is to use a Timer, that looks every 100 ms for changes/differences in some parameters and then update the viewer. This has also its limitations of course.
What would be the recommendation from the experts?
Many thanks in advance! All the best, Kees
  3 Comments
Rik
Rik on 1 Mar 2018
As far as I understand it, Matlab is still calculating most things sequentially, so a shared flag should work (exceptions would be the obvious stuff like parfor, and less obvious things like optimized internal code).
Also, you wrote your reply in the answer field, which is generally not advisable, as their order can change based on upvotes and being accepted or not. So to better structure threads of discussion, it is in general better to just replies as comments.
Stephen23
Stephen23 on 1 Mar 2018
Kees de Kapper's "Answer" moved here:
Thanks Rik for your comment. I'm doing such a thing at the moment, however, it does not always help since updates of parameters have been executed sequentially and not simultaneously.
My idea of using a timer is that the chance of all involved parameters are updated before the next timer-callback is executed.
Another issue that I have (and maybe it is my limited Matlab skills) that you need to keep track of all the listeners. Sometimes when you have an error, not all objects and listeners are properly removed/deleted. Than you will get unintended callbacks. Using a timer it might be a bit easier, but I don't know for sure.

Sign in to comment.

Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!