LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Window doesn't close wheh Call Library Function Node set to Run in Any Thread

This is a problem regarding Call Library Function Nodes running in the UI thread or any thread.

I have a camera which has its own API supplied as a dll. I have created a set of VI wrappers which each call a function in the dll through a Call Library Function Node.

Initially each CLFN was set to 'Run in the UI thread' (the default).

To start the camera streaming images I call (through a CLFN)

     ICubeSDK_Start(int CamIndex, Hwnd, ImgHandle, bool Preview, bool callback);

 

If Preview = True then the image is displayed in a preview window.

If ImgHandle = NULL a default preview window is used.

In the CLFN definition I define:
ImgHandle as a U32
Preview as a I32


To stop the camera streaming images I call

    ICubeSDK_Stop(int CamIndex)

 

 

In the actual implementation I set ImgHandle = 0 (NULL) and Preview = 1 (true).

This all works fine, and a preview window is opened and images displayed. When I call ICubeSDK_Stop the preview window is closed.

However, I would prefer to set the CLFN to 'Run in any thread' because
a) when run in the UI thread the preview window randomly gets sent to the back when I switch focus between open VI windows (presumably because it is in the same thread as the VIs)
b) I don't want to put unnecessary stuff in the UI thread
c) my (naive?) understanding is that it is safer to run in any thread

So I have set all CLFNs to 'Run in any thread'

When I do this the preview window opens OK, and behaves like any other non LabVIEW controlled window in terms of focus. But when I call ICubeSDK_Stop() the preview window does not get closed properly, it just shows a blank image. I can't close it manually, there is no X in the corner and no option to close it from the taskbar. To get rid of it I have to close the LabVIEW project it is spawned from, which often results in a crash. It does appear as a separate item in task manager but if I 'end process' it, LabVIEW closes (and often crashes) as well.

If I change only the CLFNs that call the Start and Stop functions back to 'Run in the UI thread' then it all works fine again, except that the preview window gets sent to the back randomly as before.

So, what do I have to do to get the preview window to close properly if I set the CLFN to 'Run in any thread'.
Alternatively, is there a way to close the window programmatically (ie force it to close) after I have called ICube_Stop.

Thanks
DAve

 

0 Kudos
Message 1 of 2
(2,256 Views)

Hi Dave,

 

The "Run In UI Thread"  switches from the thread the VIs currently executing in to the user interface thread. If you select "Run in Any Thread", the Call Library Function Node continues in the currently executing thread. By default, all Call Library Function Nodes run in the User Interface thread.

Before you configure the Call Library Function Node to run in any thread, you have to make sure that the code is thread safe. Code is thread safe when it does not store any global data (e.g. global variables, files on disks, etc.), does not access any hardware, does not make calls to any functions, libraries or drivers that are not thread safe.

Unfortunately, since you said that your DLL accesses hardware, it is not recommended to use "Run in Any Thread." This is probably why you are seeing the crash.

If your preview window gets sent to the back you can programmatically bring it forward. Here is an example of how this can be done: http://decibel.ni.com/content/docs/DOC-4551

 

If you want to completely close the window down you can do so as described in this link: http://digital.ni.com/public.nsf/allkb/81E9C1441900FFCE8625748F0055DBB0?OpenDocument

 

I also thought you might find this useful: http://zone.ni.com/devzone/cda/tut/p/id/3009

 

I hope this helps.

Regards,

Mahdieh G
Applications Engineer
National Instruments UK&Ireland
0 Kudos
Message 2 of 2
(2,239 Views)