LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Async timers and access GUI from the timer (threaded) callback.

I am in the process of converting a LabWindows 2017 app over to use Async Timers.  It has been going well, so far, but then I hit a snag.

 

The existing Timer callbacks will call functions that pop up dialog boxes to report system errors. Now they cannot, due to error -128:

 

(return value == -129 [0xffffffffffffff7f]). This panel operation can be performed (if a top-level panel) only in the thread in which the panel was created, or (if a child panel) only in the thread in which the top-level parent panel was created.

 

Before I go to rearchitect this large program, I wondered if there was some other way to acess these panels from the Async Timer thread?

0 Kudos
Message 1 of 6
(1,363 Views)

At the end of some of our timer callbacks we would call some function like this:

 

Function ();

 

That function could end up trying to access PANEL gui elements.  Some help file reading led me to this:

 

PostDeferredCall ((DeferredCallbackPtr)Function , NULL);

 

This allows that function to be called later by the main thread. Or so it seems. It seems to work.

 

Is this safe?

 

0 Kudos
Message 2 of 6
(1,346 Views)

Yes, PostDeferredCall will handle the operation over to the main thread, which also runs your main() function. 

 

Alternatively you can load/unload your panels from the async timer thread.

Load them when async timer callback runs for the first time, and unload when the timer is discarded.

 

Async timers have an input parameter that tells you how many times the callback has fired. You can use it to detect the first time. 

 

Also, you can implement an EVENT_DISCARD in the timer callback, which tells you when the timer is discarded.

 

Hope this helps. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 6
(1,313 Views)

I have used an alternative method with ordinary threaded functions: use PostDeferredCallToThread () to call a function that is to be executed in a specific thread. Call CmtGetCurrentThreadID () in the threaded function to retrieve the thread ID to use. I have not tried it with async timers, but you may want to try it.

 



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 4 of 6
(1,291 Views)

Roberto -- does this imply one can make an idle thread, and just dispatch functions there when needed using PostDeferredCallToThread ()?  As long as the functions are thread-safe, I suppose?

0 Kudos
Message 5 of 6
(1,285 Views)

I never tried such a framework but I don't see a reason why it should not work, provided the idle thread function processes events.



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 6 of 6
(1,269 Views)