LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Transparent Ring not updated using asynchronous timer callback

Hello All,
in my CVI application (CVI 8.1, WinXP Prof.) I have to connect to a remote TCP server. Since the bandwith is limited, this may take a certain amount of time. Because this operation blocks the application event handling I decided to bring up a status window beforehand to inform the user that the application is trying to contact the server. That works fine so far. To show that the system is still alive I added a picture ring to the status panel that is "animated" using an asynchronous timer. This works fine as long as the background color of the ring control is not transparent. See the attached example code for a demonstration. In the example code the TCP server connection call is replaced by a Delay() call for simpleness but the behaviour is the same.
 
Does anyone have an idea?
 
Thanks!
0 Kudos
Message 1 of 2
(2,862 Views)
Hello Lenin,

In many cases, when you perform an action on a UI panel that involves redrawing all or part of the panel, it is necessary for the thread that owns the panel to process events, in order to paint the panel properly.

The function SetCtrlVal usually does not require event processing, but in some instances, such as when the control is overlapped, or when you are dealing with transparent bitmaps, then it is necessary to process events in order to redraw the panel properly. Notice that in your demo, the control on the right will finally redraw itself as soon as your program calls RunUserInterface (which allows events to be processed).

In general, even if you didn't have drawing problems, it is not a good idea to block UI threads for a significant amount of time, since oftentimes there are system messages (clipboard changes, etc...) which require events to be processed synchronously by every UI thread on the system. When a thread is blocked, deadlocks and other problems can arise.

So my suggestion to you would be: instead of having a secondary thread (the asynctimer thread) update the blocked UI, why not do the TCP work in a separate thread that you create explicitly, and do the UI updates in the main UI thread, inside a timer control callback for example, in which case the event processing will happen automatically.

Luis
0 Kudos
Message 2 of 2
(2,855 Views)