04-13-2009 01:09 PM
Help, I'm stumped!
I have an application that updates data in multiple panels via timer callbacks. I thought it would be nice to put the panel updates in an async timer so moving one panel with the mouse does not pause all panel updates. But it's not working out very well. Many of the panels contain table controls that will periodically flash off and on - but only when using the async timer. It's fine if I just use the regular timer callbacks. I've tried all the tricks, setting ATTR_VISIBLE to 0, update, then set ATTR_VISIBLE to 1. Took out any SetTableCellVal and replaced with SetTableCellAttribute. I also made sure it wasn't the active control, and I don't call ProcessSystemEvents, or ProcessDrawEvents. I commented out updating all but one of the panels in the async timer routine and I don't see the flashing too often, but once I start adding more panels for the async timer to update - I'll see flashing again. The flashing is not regular - it may happen every update, then not for a while etc. My async timer is pretty slow at only 2x a second. Any ideas?
Thanks.
Angie
04-14-2009 03:56 PM
All async timer callbacks run on a single thread that's not your main thread for the application, I'm not sure what priority. It could be you're seeing the effect of thread scheduling / thread priority.
Regular timers run on the main thread.
I think there may be restrictions in re callbacks and GUI operations from threads other than the thread that loaded the panel -so maybe that's come into play as well.
Menchar
04-15-2009 09:01 AM
04-15-2009 12:25 PM
Hi Angie,
Can you be more specific about the flashing that you're seeing. I assume all the flashing happens when inside a single call SetTableCellVal or SetTableCellAttribute. Is that correct? Does the flashing consist of all the cells changing their values gradually, one a time? Or are you seeing the plain background of the table appearing over the old frame before the new frame is completely drawn?
Finally, are you able to reproduce this flashing with a simple table in a panel, and a single async timer that writes new values to the table?
Luis
04-15-2009 12:51 PM
04-15-2009 12:53 PM
Sorry about that last post - it doesn't appear to be taking my carriage returns!!! Hope you can still understand it.
Angie
04-16-2009 12:16 PM
Hi Angie,
I'm attaching a sample program that I wrote that updates a table via a timer, with several permutations: with or without hiding the table, single-threaded vs. multi-threaded (i.e. with a UI timer or an async timer) and setting one cell at a time versus setting the entire range at once. What I found is that the entire table does flash off and then on, if and only if I hide the table around the code that sets its values. This is a strategy that is used sometimes to disable unnecessary drawing, but it seems to not work very well with multithreaded programs. It seems as if entering a critical section in the code (which is necessary in multi-threaded programs) is causing system messages to be sent to the window that force a redraw. And if the control is hidden at the time, then the panel is redrawn without the control, which results in flashing.
Having said that, I could not get the table to flash unless I toggled its visibility. What can happen even without the visible/invisible flashing is that if you set the values of the table one cell at a time (i.e. using SetTableCellVal) you see the values crawling through the table gradually, which can produce an effect similar to flashing. The strategy that you should use to avoid this is to set them all at once (i.e. using SetTableCellRangeVals).
Take a look at the attached program for some ideas.
Luis