LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract a function from inside a callback

Hi!

 

I'm building a program that communicates with another device using network streams and variables. When the connection is down I attempt to reconnect every 1 second, using an AsyncTimer. The timer calls a callback, "tryCommunicate()" which in turn runs a couple of functions eventually resulting in a call to CNVCreateReader(). The documentation for CNVCreateReader states that having the function inside a callback can cause a deadlock - which I'm experiencing. So I need to extract the call to CNVCreateReader to outside callbacks, but I can't for the life of me figure out how that's supposed to happen.

 

  • I need to be able to reinitialize the communication by killing the old reader and creating a new one if the connection is broken without shutting down the user interface.
  • I cannot use PostDeferredCall to extract the CNVCreateReader because that requires another callback which the function is run in, same problem.

This is probably a very common user case. How am I supposed to construct this without having CNVCreateReader in a callback in one way or another?

 

Thanks.

0 Kudos
Message 1 of 2
(786 Views)

Create thread with an infinite loop (that you can terminate any time you want, of course) and inside it, check a global flag variable, which you set in the callback and if it is set then call your function and than reset it back in the thread.

 

Put some sleep in the loop not to overwhelm the cpu.

 

Hope this helps

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 2
(776 Views)