LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

A question about the cvi's callback function

My question is that if a routine fallen into a callback and it needs to take  long time to finish, does it will affect the main thread running? the callbak format can be introduced by a button control, the PostDeferredCallToThread() or a timer's .

 

 

David

0 Kudos
Message 1 of 3
(4,200 Views)

There is not a unique answer to this question.

 

The main thread is in charge of handling all UI events; for this reason a long-lasting control callback (including a UI timer callback) will surely affect the main thread: if the user presses a button, it will not handled until the long callback terminates. A solution to this is to call ProcessSystemEvents () periodically inside the long lasting callback: be warned that this could lead to unpredictable / unswanted effects. This has been discussed several times in the forum: a search for that command will return a lot of discussion to study.

 

Asynchronous timers are executed in a separate thread, so they have no effect on the main thread, and vice versa. The same applies to threads other that the main one and functions called with PostDeferredCallToThread (). Multithreading implies some precaution on data access between threads but I suppose it is not the argument of your question; nevertheless, you must confine the user interface so that the operator is not permitted to use the results of the long lasting callback until it is finished (or, said another way, he must be informed that processing is running).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(4,182 Views)

Thank you Roberto.

0 Kudos
Message 3 of 3
(4,160 Views)