LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Tables flashing only when using async timer

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

0 Kudos
Message 1 of 7
(4,615 Views)

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

0 Kudos
Message 2 of 7
(4,588 Views)
Thanks for responding.It's a shame it won't work out, it's a great way to keep mouse events etc, from interfering with panels updating.  Everything seems to work nicely except the tables flashing.  Oh well.Angie 

 

0 Kudos
Message 3 of 7
(4,574 Views)

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

 

 

0 Kudos
Message 4 of 7
(4,563 Views)
Hi Luis,It’s the entire table that “flashes”.  The background (row/column headers), everything.  It’s a fairly large program with multiple input threads (running at ABOVE_NORMAL_PRIORITY), and multiple panels updating at 1 to 2 times a second.Here’s a code snippit of what I finally broke the async timer code down to..and it still flashed.  Just to note, the timer is set to trigger 2 times a second, and the panel handle is declared volatile.  FWIW I’m using the Windows visual styles for all the panels.I haven’t tried to create a new simple project with just one panel and the async timer…I’ll try that next when I get a chance…I’m trying to get this program to the customer this week.  I hate to change too much at this late date, but if I can figure it out quickly I like the async timer solution so much better. Here’s the stripped down async timer code:_______________________________________________static int              count=0; int CVICALLBACK Thread_AsyncTimer (int reserved, int timerId, int event, void *callbackData, int eventData1, int eventData2){switch (event)               {               case EVENT_TIMER_TICK:                              {                              count++;                              //TWICE A SECOND UPDATES:if ((count % 2) == 0){SetCtrlAttribute (panel, tablecontrol, ATTR_VISIBLE, 0);     //…commented out code SetCtrlAttribute (panel, tablecontrol, ATTR_VISIBLE, 1);}                                                                                         //ONCE A SECOND UPDATES:                                                                   {                              //…commented out code.                              if (count >= 2)                                             count = 0;                              break;                              }               }return 0;} 
0 Kudos
Message 5 of 7
(4,558 Views)

Sorry about that last post - it doesn't appear to be taking my carriage returns!!!  Hope you can still understand it.

Angie

0 Kudos
Message 6 of 7
(4,557 Views)

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

 

0 Kudos
Message 7 of 7
(4,533 Views)