09-04-2022 12:51 PM
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?
09-06-2022 03:30 AM
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.
09-06-2022 04:19 AM
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.
09-06-2022 04:22 AM
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?
09-06-2022 06:51 AM
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?