LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NI Vision Custom Control fails on multithreading

Hello,

I want to use NI Vision Custom Control (ImageControlSetAttribute) in a multithreading environment, but it seems like this is incompatible with Multithreading. The "LiveThreadFunction" here triggers the ImageControl_SetAttribute but it doesn't seem to display in the UI. Can anyone please help me with how to correct this?

 

 

 

0 Kudos
Message 1 of 5
(1,132 Views)

Most likely the ImageControl is implemented as an ActiveX component in order to reuse code from LabVIEW rather than fully integrating this into LabWindows/CVI. Most ActiveX components are apartment threaded. This is a special threading mode, which means the ActiveX control doesn't care in which thread it runs, as long as any call to it is always from the same thread. This generally means that the creation of the object needs to occur in the same thread than any calls to its methods.

 

Possible solutions:

 

Adding a user timer to your panel that polls a queue or notifier to see if there is a new image present in it. And posting the image to that queue or notifier from your threaded callback.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 5
(1,092 Views)

In the scenario depicted by Rolf, probably you could simply pass the image to a function called with PostDeferredCall: that function is executed in the main thread which is handling the UI and most likely owning the Activex control.



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 3 of 5
(1,083 Views)

Thank You for the suggestion, I tried to run/create it in a different thread altogether, but in such a case, the main thread(UI) freezes, as I am making a continuous data acquisition in a continuous loop. Will a short refresh Timer() help in such a case? If I am not wrong, a Timer function works similarly, right? 

0 Kudos
Message 4 of 5
(1,082 Views)

Well, I have no experience on NI Vision module but freezing the main thread is definitely unexpected when dealing with multithreading!

Since you already were using multithreading, which modifications have you introduced in the code that resulted in such a freeze?



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 5 of 5
(1,074 Views)